Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

ClickDetector on Part Not Teleporting A Player?

I tried making a model with a part named "location", a part named "plate", and a script inside the model. The "plate" has a ClickDetector in it, and I tried putting inside the script this code below to see if, when the plate is clicked, it will set the CFrame of the player's LeftFoot to the CFrame of the "location" part:

local plate = script.Parent.plate
local location = script.Parent.location

plate.ClickDetector.MouseClick:Connect(function(plr)
plr.Parent.Parent.Workspace.plr.LeftFoot.CFrame = location.CFrame
end)

I realize that "plr" refers to the player in the "Players", not the "Workspace", and I think that's the problem. I don't know how to fix it, though, so please help me out if you know how to!

2 comments

0

The funtion searches for a object named "plr" not the player. do plr.Character to get the character.

0

commag, this didn't fix it. Are you sure that the ClickDetector refers to the objects in Workspace? I printed "plr", "plr.Parent", and "plr.Parent.Parent". It printed my name, then "Players", and the name of the game.

1 answer

✓ Accepted answer

Click Detectors return objects, not players. You could try

local plate = script.Parent.plate
local location = script.Parent.location
plate.ClickDetector.MouseClick:Connect(function(plr)
if plr.Parent:FindFirstChild("HumanoidRootPart") then
plr.Parent.HumanoidRootPart.CFrame = CFrame.new(location.CFrame + CFrame.new(0,2,0))
end
end)

If for some reason this doesn't work, just comment on this and I'll fix it :)

This discussion is preserved as it was. New answers, comments, and votes are closed.