So, I'm trying to make a RoleGui and there were many errors with it, but luckily I was able to fix them except one where I keep getting a "nil value"?
Here's the code: local survivors = {}
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(char) local playerRole = Instance.new("StringValue") playerRole.Name = "PlayerRole" playerRole.Parent = player
while wait(20) do local plrs = game.Players
for _,players in pairs(game.Players:GetChildren()) do
if #game.Players:GetChildren() == 1 then players.PlayerGui:WaitForChild("RoleGui").WaitingText.Visible = true else players.PlayerGui:WaitForChild("RoleGui").WaitingText.Visible = false local randomPlayer = plrs:GetPlayers(math.random(1,#plrs:GetPlayers()))
randomPlayer:WaitForChild("PlayerRole").Value = "Murder"
randomPlayer.PlayerGui:WaitForChild("RoleGui").Frame.RoleText.TextColor3 = Color3.fromRGB(255,0,0)
randomPlayer.PlayerGui:WaitForChild("RoleGui").Frame.RoleText = randomPlayer:WaitForChild("PlayerRole").Value
local clone = game.ServerStorage["Murder Knife"]:Clone()
clone.Parent = randomPlayer.Backpack
for _,player in pairs(plrs:GetPlayers()) do
if player ~= randomPlayer then player.PlayerGui:WaitForChild("RoleGui").Frame.RoleText.TextColor3 = Color3.fromRGB(0,255,0) player:WaitForChild("PlayerRole").Value = "Survivor" player.PlayerGui:WaitForChild("RoleGui").Frame.RoleText.Text = player:WaitForChild("PlayerRole").Value player.PlayerGui:WaitForChild("RoleGui").Frame:TweenPosition(UDim2.new(0.339,0,0.24,0),"Out","Elastic",0.7) table.insert(survivors,player) wait(5) player.PlayerGui:WaitForChild("RoleGui").Frame:TweenPosition(UDim2.new(0.339,0,1.5,0),"In","Elastic",0.7) end end end
end
end
end)
end)
First of all just do
game.Players.PlayerAdded:connect(function(plr) local playerrole = instance.new("StringValue") playerrole.Name = "PlayerRole" playerrole.Parent = plr end)
U dont need to add characteradded, also u dont need :WaitForChild() but that isnt the problem the problem is that for ur adding script u forgot the end) so it never actully made the value because it caused a error and u should put the value for a seperate script. That should work if it does please accept my answer