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

How to teleport player with clickdetector?

Asked by 2 years ago

I want to make players get teleported to a certain spot after clicking a button, my code below, don't know what I'm doing wrong.

place = CFrame.new(123.5,3608.89,446)
script.Parent.ClickDetector.MouseClick:Connect(function(p)
    local humanoid = p.Parent:findFirstChild("Humanoid")
    if (humanoid ~= nil) then
        humanoid.Torso.CFrame = place
    end
end)

2 answers

Log in to vote
0
Answered by
boredlake 256 Moderation Voter
2 years ago

Since AProgrammR's script didn't work, this might work better:

place = CFrame.new(123.5,3608.89,446)
script.Parent.ClickDetector.MouseClick:Connect(function(p)
local char = p.Character
    if char then
        char.Torso.CFrame = place
    end
end)

The concept is similar, just adapted for R6 rigs, and without the semicolon.

0
There was a problem stopping me from clicking it, this worked, and AProgrammR's probably would've too, sorry! Uniplier 83 — 2y
Ad
Log in to vote
0
Answered by 2 years ago

"p" does not return the player's character but rather returns the player object. You can get the character by using p.Character. Try:

place = CFrame.new(123.5,3608.89,446)
script.Parent.ClickDetector.MouseClick:Connect(function(p)
    if p.Character then
        p.Character.HumanoidRootPart.CFrame = place;
    end
end)

Hope it helps!

0
Sorry, it doesn't seem to work Uniplier 83 — 2y

Answer this question