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 7 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:

script.Parent.Parent.Touched:connect(function(hit)
    if hit.Parent.Parent:FindFirstChild('Humanoid') then
        hit.Parent.Parent.Torso.CFrame = CFrame.new(56, 5.1, -5116.002)


    end
end)

Please help me thank you.

2 answers

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

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

local part = script.Parent -- It's good practice to index your items, it's easier to read and visualize.  
part.Touched:connect(function(hit) -- Parent removed
-- Removed a parent here as well
-- Standard practice to make sure what we hit isn't nil 
    if hit and hit.Parent then 
    -- grabs player from character (hit.Parent)
        local player = game.Players:GetPlayerFromCharacter(hit.Parent) 
        -- Make sure it's a player and their character is loaded.
        if player and player.Character then
            local hum = player.Character:findFirstChild("Humanoid") 
            -- Don't want to move if they just died on the teleporter
            if hum and hum.Health > 0 then
                player.Character:MoveTo(Vector3.new(56, 5.1, -5116.002))
            end
        end
    end
end)
Ad
Log in to vote
1
Answered by
qVision 12
7 years ago

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

local telestart = script.Parent
local teleend = game.Workspace.TeleEnd

function teleportPlayer(part)
    local torso = part.Parent:FindFirstChild("Torso")
        torso.CFrame = CFrame.new(teleend.Position) + Vector3.new(0,10,0)
        print(1)    --For testing
    end



telestart.Touched:connect(teleportPlayer)

Answer this question