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

How to make Script go into players torso when joined?

Asked by 10 years ago

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

3 answers

Log in to vote
1
Answered by
Nickoakz 231 Moderation Voter
10 years ago
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)
Ad
Log in to vote
0
Answered by
Cizox 80
10 years ago
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)

Log in to vote
0
Answered by 10 years ago
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)

0
You have to wait for the toro. It's not always there directly. DhatBoiiPapi 10 — 10y

Answer this question