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)
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.
"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!