Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
-1

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

Asked by 10 years ago
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

Log in to vote
0
Answered by
Ekkoh 635 Moderation Voter
10 years ago

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
0
How can I put a stringvalue in players? NinjoOnline 1146 — 10y
0
Refer to edit :) Ekkoh 635 — 10y
Ad

Answer this question