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

ClickDetector on Part Not Teleporting A Player?

Asked by 5 years ago

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!

0
The funtion searches for a object named "plr" not the player. do plr.Character to get the character. dannyspain 2 — 5y
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. User#28017 0 — 5y

1 answer

Log in to vote
1
Answered by
commag 228 Moderation Voter
5 years ago

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

Ad

Answer this question