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

Why do I keep getting a nil value if OBVIOUSLY there is a value being shown in the player?

Asked by 4 years ago

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)

1player.CharacterAdded:Connect(function(char)
2 
3    local playerRole = Instance.new("StringValue")
4    playerRole.Name = "PlayerRole"
5    playerRole.Parent = player

while wait(20) do local plrs = game.Players

for _,players in pairs(game.Players:GetChildren()) do

1if #game.Players:GetChildren() == 1 then
2 
3    players.PlayerGui:WaitForChild("RoleGui").WaitingText.Visible = true
4else
5 
6players.PlayerGui:WaitForChild("RoleGui").WaitingText.Visible = false
7    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

01if player ~= randomPlayer then
02 
03      player.PlayerGui:WaitForChild("RoleGui").Frame.RoleText.TextColor3 = Color3.fromRGB(0,255,0)
04 
05    player:WaitForChild("PlayerRole").Value = "Survivor"
06 
07     player.PlayerGui:WaitForChild("RoleGui").Frame.RoleText.Text = player:WaitForChild("PlayerRole").Value
08 
09    player.PlayerGui:WaitForChild("RoleGui").Frame:TweenPosition(UDim2.new(0.339,0,0.24,0),"Out","Elastic",0.7)
10 
11    table.insert(survivors,player)
12 
13    wait(5)
14 
15    player.PlayerGui:WaitForChild("RoleGui").Frame:TweenPosition(UDim2.new(0.339,0,1.5,0),"In","Elastic",0.7)
16 end
17 
18    end
19end

end

end

end)

1 answer

Log in to vote
1
Answered by
TNTIsLyfe 152
4 years ago

First of all just do

1game.Players.PlayerAdded:connect(function(plr)
2local playerrole = instance.new("StringValue")
3playerrole.Name = "PlayerRole"
4playerrole.Parent = plr
5end)

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

0
Thank you very much, that was one of the problems with it, the other was something else but this 100% helped too! CataclysmicDev 46 — 4y
Ad

Answer this question