Ok so I want to teleport a player to a position when they touch a brick, this is what I have.
function touch(hit) local h = script.Parent:findFirstChild("Humanoid") if h then h.Parent.Torso.CFrame = CFrame.new(Vector3.new(-27.4, 0.5, 74)) end end script.Parent.Touched:connect(touch)
It's not working, help?
Position = ( --enter where you want to tele here ) function touch(hit) local h = script.Parent:findFirstChild("Humanoid") h:MoveTo(Position) end script.Parent.Touched:connect(touch)
I'm sorry if that's not what you wanted, also to make this easier you can do
Position = game.Workspace.TeleHere.Position function touch(hit) local h = script.Parent:findFirstChild("Humanoid") h:MoveTo(Position) end script.Parent.Touched:connect(touch)
that way you can easily change the location without having to deal with (x,y,z) things
You did script.Parent:FindFirstChild("Humanoid"), Humanoid is not inside the part your script is in, so the if then statement will always be false. You were also trying to move the torso that was supposedly inside humanoid, which it isn't it's inside your character model, so that is hit.Parent that would get you your character model. Now your script may error out if say, you're dead, torso is flying and gets deleted for being outside the map, and one of your other body parts touches the brick. So you may want to have the script search for the torso instead.
function touch(hit) --Function to be called. if hit.Parent:findFirstChild("Torso") then --Checks if Torso exists. hit.Parent.Torso.CFrame = CFrame.new(Vector3.new(-27.4, 0.5, 74)) --Move the torso position. end end script.Parent.Touched:connect(touch) --Fires function.