Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Touched is not a valid number of model?

Asked by 8 years ago

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:

1script.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
7end)

Please help me thank you.

2 answers

Log in to vote
0
Answered by
Azarth 3141 Moderation Voter Community Moderator
8 years ago

Your parents don't point to the part, they're pointing to the model. Take one Parent off.

01local part = script.Parent -- It's good practice to index your items, it's easier to read and visualize. 
02part.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(Vector3.new(56, 5.1, -5116.002))
14            end
15        end
16    end
17end)
Ad
Log in to vote
1
Answered by
qVision 12
8 years ago

I also made a teleporter, but I used another part for the player to teleport to.

01local telestart = script.Parent
02local teleend = game.Workspace.TeleEnd
03 
04function teleportPlayer(part)
05    local torso = part.Parent:FindFirstChild("Torso")
06        torso.CFrame = CFrame.new(teleend.Position) + Vector3.new(0,10,0)
07        print(1)    --For testing
08    end
09 
10 
11 
12telestart.Touched:connect(teleportPlayer)

Answer this question