I have a large brick. I would like a player to teleport to a certain area on humanoid touch, but not sure how to script it.
Put this script in the block being touched.
1 | place = CFrame.new( 0 , 0 , 0 ) -- Where you want the player to go on touched |
2 | script.Parent.Touched:connect( function (p) --Creating the function |
3 | local humanoid = p.Parent:findFirstChild( "Humanoid" ) --Trying to find the humanoid |
4 | if (humanoid ~ = nil ) then -- Checking if what touched it IS a player. |
5 | humanoid.Torso.CFrame = place -- Moves the torso to what is specified in the place variable |
6 | end |
7 | end ) --Ending the fuction, if you see on the function line above there is an unclosed parenthesis that I am closing here. |
If this does not work, reply with the error please so I can fix it, because I sometimes make silly errors
You use the Touched event and the MoveTo method.
01 | Brick = script.Parent -- 1 |
02 | AnotherBrick = game.Workspace.AnotherBrick -- 2 |
03 |
04 | Brick.Touched:connect( function (part) -- 3 |
05 | if part.Parent.Humanoid then -- * |
06 | if part.Parent.Humanoid.Health > 0 then -- 4 |
07 | part.Parent:MoveTo(AnotherBrick.Position) -- 5 |
08 | end |
09 | end |
10 | end ) |
11 |
12 | -- 1 The teleportation brick |
13 | -- 2 The destination of the teleportation brick |
14 | -- 3 When the teleportation brick is touched, (part) is the part the touched it. |
15 | -- 4 If it was touched by a part within a character model, and the character is alive, |
16 | -- 5 Move the character model to the destination. |
17 |
18 | --* Suggesting that the part that touched the teleportation brick is a leg or something. If the teleportation brick is as tall as a Character, then you might have to script something else in case the Character's Hat touched the brick instead. |
This works for me just be careful I used this with R6 it may not work with R15 or Rthro.
1 | place = CFrame.new(- 61.64 , 11.365 , 1.225 ) -- Where you want the player to go on touched |
2 | script.Parent.Touched:connect( function (p) --Creating the function |
3 | local humanoid = p.Parent:findFirstChild( "Humanoid" ) --Trying to find the humanoid |
4 | if (humanoid ~ = nil ) then -- Checking if what touched it IS a player. |
5 | humanoid.Torso.CFrame = place -- Moves the torso to what is specified in the place variable |
6 | end |
7 | end ) --Ending the fuction, if you see on the function line above there is an unclosed parenthesis that I am closing here. |
1 | local teleportpart = script.Parent -- The part you want to teleport the player |
2 | teleportpart.Touched:Connect( function (hit) |
3 | if hit.Parent.HumaniodRootPart then |
4 | hit.Parent.HumanoidRootPart.Position = Vector 3. new( 0 , 0 , 0 ) -- What ever X,Y,Z you want |
5 | end |
6 | end ) |
Locked by youtubemasterWOW, zblox164, and JesseSong
This question has been locked to preserve its current state and prevent spam and unwanted comments and answers.
Why was this question closed?