The value is created and parented fine but the values in workspace do not change. (PInfo is a folder in workspace)
function onPlayerEntered(newPlayer) local All = game.Workspace.PInfo:GetChildren() local Num = Instance.new("NumberValue") Num.Name = "PadNum" Num.Parent = newPlayer newPlayer:WaitForChild("PadNum") local PadNum = newPlayer:FindFirstChild("PadNum") for i, v in pairs(All) do if PadNum.Value == 0 then else if v.Claimed.Value == false then v.Owner.Value = newPlayer.Name v.Claimed.Value = true PadNum.Value = v.Name else end end end end game.Players.ChildAdded:connect(onPlayerEntered)
You're trying to set a NumberValue's Value to a string.
function onPlayerEntered(newPlayer) local All = game.Workspace.PInfo:GetChildren() local Num = Instance.new("NumberValue") Num.Name = "PadNum" Num.Parent = newPlayer newPlayer:WaitForChild("PadNum") local PadNum = newPlayer:FindFirstChild("PadNum") for i, v in pairs(All) do if PadNum.Value == 0 then else if v.Claimed.Value == false then v.Owner.Value = newPlayer.Name v.Claimed.Value = true PadNum.Value = v.Name else end end end end game.Players.ChildAdded:connect(onPlayerEntered)
After we break down the code and do a little refactoring, we are essentially presented with
game.Players.PlayerAdded:connect(function(newPlayer) local All = game.Workspace.PInfo:GetChildren() local PadNum = Instance.new("NumberValue") PadNum.Name = "PadNum" PadNum.Parent = newPlayer for i, v in pairs(All) do if PadNum.Value ~= 0 then if v.Claimed.Value == false then v.Owner.Value = newPlayer.Name v.Claimed.Value = true PadNum.Value = v.Name end end end end)
Which leaves us with a slight problem at PadNum.Value = v.Name
; PadNum is a NumberValue, but v.Name is a string. You may need to reconsider either what you are setting as PadNum.Value
, or reconsider how you are recording your information and in which formats.
First off, line 9 and line 14 so in line 9, you define PadNum as an IntValue, but then in line 14, you want its value to be a string. That might be what breaks it.