function OnPlayerAdded(NewP)
local Player = game.Workspace:FindFirstChild(NewP.Name) local Torso = Player:FindFirstChild(Torso) wait(4) Scr = game.Workspace.IScript:Clone() Scr.Parent = game.Workspace:FindFirstChild(Torso) wait(4) Val = game.Workspace.it:Clone() Val.Parent = game.Workspace:FindFirstChild(NewP.Name)
end game.Players.PlayerAdded:connect(OnPlayerAdded)
It says 20:44:56.229 - Workspace.Script:4: attempt to index local 'Player' (a nil value)
what im trying to do is put a script in the new players torso
function OnPlayerAdded(NewP) local Player = Workspace:WaitForChild(NewP.Name) --Its better to use wait for child, since the character arnt available instantly. local Torso = Player:WaitForChild("Torso") --Its better to use wait for child, since sometimes torsos arnt available instantly, also, it needs to be a quote. Scr = Workspace.IScript:Clone() Scr.Parent = Torso Val = Workspace.it:Clone() Val.Parent = Player end game.Players.PlayerAdded:connect(OnPlayerAdded)
game.Players.PlayerAdded:connect(function(player) player.CharacterAdded:connect(function(character) local torso = character:findFirstChild('Torso') local script = Workspace:findFirstChild('IScript'):Clone() if torso then script.Parent = torso end end) end)
Inserts the script every time the player respawns. If you don't want that, then here is the alternate:
game.Players.PlayerAdded:connect(function(player) local character = player.Character local torso = character:findFirstChild('Torso') local script = Workspace:findFirstChild('IScript'):Clone() if torso then script.Parent = torso end end)
game.Players.PlayerAdded:connect(function(player) local char = player.Character local torso = char:WaitForChild("Torso") local script = Workspace:findFirstChild("IScript"):Clone() if torso ~= nil then script.Parent = torso end end)