Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How can I get a script to check a players role?

local sheriff   
local murderer
local innocent  = {}


local players = game.Players:GetPlayers()
murderer = players[math.random(#players)].Name
sheriff = players[math.random(#players)].Name
for i,v in pairs(players) do 
    if v.Name ~= sheriff and v.Name ~= murderer then 
        table.insert(innocent, v.Name)
    end
end

print("MURDERER: "..murderer,"SHERIFF: "..sheriff, "INNOCENTS: "..table.concat(innocent,", "))

Ok so this picks a random player to be murder, etc you all know how the game works, and now I need another script to check if the player is murder, or whatever they are, so it can tell the player that they are whatever they are

1 answer

✓ Accepted answer

If you're checking within the same script just say if plrVariable == muderer then. If you're checking from another script, I'd make a StringValue in each player called Role or something and set its value to whatever the player's role is.

I would do something like this-

Script 1:

local Players = Game:GetService("Players")

function PlayerJoined(plr)
	print(plr.Name .. " joined the server.")
	local role = Instance.new("StringValue")
	role.Name = "Role"
	role.Value = "default" -- you could replace default with whatever
	role.Parent = plr
end

for _, plr in pairs(Players:GetPlayers()) do
	PlayerJoined(plr)
end

Players.PlayerAdded:connect(PlayerJoined)

Script 2:

if plrVariable.Role.Value == "murderer" then
	print(plrVariable.Name .. " is the murderer.")
end

2 comments

0

How can I put a stringvalue in players?

0

Refer to edit :)

This discussion is preserved as it was. New answers, comments, and votes are closed.