I have a string value that was inserted into the workspace called "Players". When a player is added into the game it create another string value having the parent be "Players" However it keeps giving this output and will not work. 17:31:19.224 - Workspace.PLR:9: attempt to call field 'Players' (a userdata value).
game.Players.PlayerAdded:connect(function(plr) wait(.5) local k = Instance.new("StringValue",game.Workspace.Players) k.Name = plr.Name k.Value = plr.Name end) game.Players.PlayerRemoving:connect(function(plr2) if game.Workspace.Players:FindFirstChild(plr2.Name) then game.Workspace.Players(plr2.Name):remove() end end)
Ex, game.Workspace.Players:FindFirstChild(plr2.Name):Destroy()
or game.Workspace.Players[plr2.Name]:Destroy()
. I'll be using FindFirstChild.
Your code should look somewhat like this,
-- regular script game.Players.PlayerAdded:connect(function(plr) wait(.5) local k = Instance.new("StringValue",game.Workspace.Players) k.Name = plr.Name k.Value = plr.Name end) game.Players.PlayerRemoving:connect(function(plr2) if game.Workspace.Players:FindFirstChild(plr2.Name) then game.Workspace.Players:FindFirstChild(plr2.Name):Destroy() end end)
Good Luck