local trigger = script.Parent function onTouch(char) local hum = char.Parent:FindFirstChild("Humanoid") --error here if hum then hum.Parent.HumanoidRootPart.CFrame = workspace.Spawn.CFrame + Vector3.new(0, 10, 0) end end trigger.Touched:Connect(onTouch()) -- here was the mistake -- please help on line 4 it says attempt to index nil with parent -- lol i accidentally added an extra set of parentheses on the last line
This means that char.Parent
doesn't exist, and you are trying to find a humanoid (this isn't exactly what it means but you get the idea.)
Also make sure that any surrounding parts are anchored (and you want them to be anchored) since .Touched
only interacts with unanchored parts.
local trigger = script.Parent function onTouch(hit) if hit.Parent:FindFirstChild("Humanoid") then local hum = hit.Parent:FindFirstChild("Humanoid") hum.Parent.HumanoidRootPart.CFrame = workspace.Spawn.CFrame + Vector3.new(0, 10, 0) end end trigger.Touched:Connect(onTouch)
And if this doesn't work, or you want it to work just for players and not NPCs (if you have NPCs in your game), you can check if it's a player as well.
local trigger = script.Parent function onTouch(hit) if hit.Parent:FindFirstChild("Humanoid") then local hum = hit.Parent:FindFirstChild("Humanoid") if game.Players:GetPlayerFromCharacter(hit.Parent) then hum.Parent.HumanoidRootPart.CFrame = workspace.Spawn.CFrame + Vector3.new(0, 10, 0) end end end trigger.Touched:Connect(onTouch)