I'm trying to make a murder mystery game to see if I can do it but I want to do that the murder doesn't become the sheriff too, I wrote a code but it won't work, Can anyone help me?
Module script:
local functions = {} local serverStorage = game:GetService("ServerStorage") local sword = serverStorage:WaitForChild("Assets"):WaitForChild("ClassicSword") local gun = serverStorage:WaitForChild("Assets"):WaitForChild("HyperlaserGun") functions.chooseRandomSherrif = function() local players = game:GetService("Players"):GetPlayers() local Sherrif = players[math.random(1,#players)] local clonedGun = gun:Clone() local sherrifTag = Instance.new("BoolValue") if Sherrif:WaitForChild("Murder") then sherrifTag.Name = "Sherrif" sherrifTag.Parent = Sherrif.Character clonedGun.Parent = Sherrif.Backpack end end functions.chooseRandomMurder = function() local players = game:GetService("Players"):GetPlayers() local Murder = players[math.random(1,#players)] local clonedSword = sword:Clone() local murderTag = Instance.new("BoolValue") if not Murder:WaitForChild("Sherrif") then murderTag.Name = "Murder" murderTag.Parent = Murder.Character clonedSword.Parent = Murder.Backpack end end return functions
Here's a better idea, use attributes. They're a new feature that are pretty much the replacement for value objects.
An example of how you can fit this into your game:
function AssignSherrif() local Player repeat Player = Players:GetChildren()[math.random(0,#Players:GetChildren())] until not Player:GetAttribute("Role") = "Murderer" Player:SetAttribute("Role", "Sherrif") -- other stuff end function AssignMurderer() local Player repeat Player = Players:GetChildren()[math.random(0,#Players:GetChildren())] until not Player:GetAttribute("Role") = "Sherrif" Player:SetAttribute("Role", "Murderer") -- other stuff end
This:
if not player.BoolValue then --some code end