So I am trying to create a teleporter but when I test it out it doesn't work. I looked in the output and it tells me "Touched is not a valid number of model"
My workspace:
-Lobby
Humanoid, Head, Part,
-Part
Mesh, Script
Script:
1 | script.Parent.Parent.Touched:connect( function (hit) |
2 | if hit.Parent.Parent:FindFirstChild( 'Humanoid' ) then |
3 | hit.Parent.Parent.Torso.CFrame = CFrame.new( 56 , 5.1 , - 5116.002 ) |
4 |
5 |
6 | end |
7 | end ) |
Please help me thank you.
Your parents don't point to the part, they're pointing to the model. Take one Parent off.
01 | local part = script.Parent -- It's good practice to index your items, it's easier to read and visualize. |
02 | part.Touched:connect( function (hit) -- Parent removed |
03 | -- Removed a parent here as well |
04 | -- Standard practice to make sure what we hit isn't nil |
05 | if hit and hit.Parent then |
06 | -- grabs player from character (hit.Parent) |
07 | local player = game.Players:GetPlayerFromCharacter(hit.Parent) |
08 | -- Make sure it's a player and their character is loaded. |
09 | if player and player.Character then |
10 | local hum = player.Character:findFirstChild( "Humanoid" ) |
11 | -- Don't want to move if they just died on the teleporter |
12 | if hum and hum.Health > 0 then |
13 | player.Character:MoveTo(Vector 3. new( 56 , 5.1 , - 5116.002 )) |
14 | end |
15 | end |
16 | end |
17 | end ) |
I also made a teleporter, but I used another part for the player to teleport to.
01 | local telestart = script.Parent |
02 | local teleend = game.Workspace.TeleEnd |
03 |
04 | function teleportPlayer(part) |
05 | local torso = part.Parent:FindFirstChild( "Torso" ) |
06 | torso.CFrame = CFrame.new(teleend.Position) + Vector 3. new( 0 , 10 , 0 ) |
07 | print ( 1 ) --For testing |
08 | end |
09 |
10 |
11 |
12 | telestart.Touched:connect(teleportPlayer) |