I am having problems with moving a player that touches a brick to somewhere else. I have tried putting 'FindFirstChild("Humanoid")' as a variable and as a part of the 'onTouched' function, but niether have worked.
This is the code I have currently.
The script is a child of Part 'Part3'.
bin = script.Parent player = game.Players:FindFirstChild("Humanoid") function onTouched(Part3) if player then player.Torso.CFrame = CFrame.new(Vector3.new(84, 160, 12)) end end bin.Touched:connect(onTouched)
I am a newbie to scripting, so I appreciate if you would explain the changes you would make to this code. Thank you in advance.
bin = script.Parent function onTouched(Part) --What was up with the three there? The Part is the part of the body hitting the "bin". if Part.Parent:FindFirstChild("Torso") then --Your Character is hitting it, not your player. Part.Parent.Torso.CFrame = CFrame.new(Vector3.new(84, 160, 12)) end end bin.Touched:connect(onTouched)
Here, I'll explain it as I go along:
bin = script.Parent function onTouched(hit) -- 'hit' is the name we assign the object that touches it if hit.Parent:findFirstChild("Humanoid") -- The hit should be a humans leg, so we see if the parent has a humanoid in it as it should be a player hit.Parent.Torso.CFrame = CFrame.new(Vector3.new(84, 160, 12)) -- The character is moved end end bin.Touched:connect(onTouched)