Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
freem
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Openai/690c794b-14ac-8002-a146-ba84ec97f888
(section)
Add languages
Page
Discussion
English
Read
Edit
Edit source
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
Edit source
View history
General
What links here
Related changes
Special pages
Page information
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== βοΈ Full Roblox Lua Script (Ready-to-Use) == Paste this in ServerScriptService as RoleAssignmentGame.lua. <syntaxhighlight lang="lua"> -- // =========================================== -- // Dynamic Role Assignment: Killer vs Detective -- // Roblox Lua Script (ServerScriptService) -- // Author: ChatGPT (GPT-5) -- // =========================================== local Players = game:GetService("Players") local RunService = game:GetService("RunService") -- CONFIGURATION ------------------------------- local GameActive = false local CriminalGoalTime = 180 local DetectiveTurnDuration = 20 local CivilianKillPenalty = 10 -- DYNAMIC ROLE DISTRIBUTION RULES ------------- local function GetRoleCounts(totalPlayers) if totalPlayers <= 6 then return 1, 1 -- 1 killer, 1 detective elseif totalPlayers <= 10 then return 2, 2 else return 3, 3 end end -- GAME STATE ----------------------------------- local Criminals = {} local Detectives = {} local Civilians = {} -- ROLE ASSIGNMENT ------------------------------ local function AssignRoles() local allPlayers = Players:GetPlayers() local totalPlayers = #allPlayers if totalPlayers < 3 then warn("Not enough players to start the game.") return false end local killerCount, detectiveCount = GetRoleCounts(totalPlayers) print(("π§© Assigning Roles | Killers: %d | Detectives: %d | Total Players: %d") :format(killerCount, detectiveCount, totalPlayers)) -- Shuffle player list local shuffled = {} for _, p in ipairs(allPlayers) do table.insert(shuffled, p) end for i = #shuffled, 2, -1 do local j = math.random(i) shuffled[i], shuffled[j] = shuffled[j], shuffled[i] end -- Assign killers for i = 1, killerCount do table.insert(Criminals, shuffled[i]) print("πͺ Assigned Killer: " .. shuffled[i].Name) end -- Assign detectives for i = killerCount + 1, killerCount + detectiveCount do table.insert(Detectives, shuffled[i]) print("π΅οΈ Assigned Detective: " .. shuffled[i].Name) end -- Remaining players = civilians for i = killerCount + detectiveCount + 1, #shuffled do table.insert(Civilians, shuffled[i]) print("π₯ Assigned Civilian: " .. shuffled[i].Name) end return true end -- END GAME ------------------------------------- local function EndGame(winner) GameActive = false print("=====================================") print(" GAME OVER! Winner: " .. winner) print("=====================================") end -- CIVILIAN EVENT HANDLERS ---------------------- local function OnCivilianKilled(victim, isTarget) if not GameActive then return end if isTarget then print("[!] Killer eliminated their target successfully.") else print("[X] Killer killed a non-target civilian! Instant defeat.") EndGame("Detectives") end end local function OnCivilianDeathEffect() for _, detective in ipairs(Detectives) do print("Detective " .. detective.Name .. "'s investigation time reduced!") end end -- GAME LOOP ------------------------------------ local function StartGame() GameActive = true print("=====================================") print("π« Game Start: Killers vs Detectives") print("=====================================") print(("Game duration: %d seconds"):format(CriminalGoalTime)) task.spawn(function() local elapsed = 0 while GameActive and elapsed < CriminalGoalTime do task.wait(1) elapsed += 1 -- Example: random civilian death events if elapsed == 60 then print("[EVENT] Civilian killed by mistake!") OnCivilianKilled("Civilian1", false) break elseif elapsed == 120 then OnCivilianDeathEffect() end if elapsed % DetectiveTurnDuration == 0 then print(("β Time: %d / %d seconds"):format(elapsed, CriminalGoalTime)) end end if GameActive then EndGame("Killers (escaped successfully)") end end) end -- MAIN ENTRY ----------------------------------- Players.PlayerAdded:Connect(function(player) print("Player joined: " .. player.Name) end) Players.PlayerRemoving:Connect(function(player) print("Player left: " .. player.Name) end) -- Wait a few seconds for all players, then assign roles and start task.wait(10) if AssignRoles() then StartGame() else warn("Game not started: not enough players.") end </syntaxhighlight>
Summary:
Please note that all contributions to freem are considered to be released under the Creative Commons Attribution-ShareAlike 4.0 (see
Freem:Copyrights
for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)