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

Simple CFrame movement script not working?

I created a script that moves a model and the player that clicks the button to a specific position (10,1.5,10). However, the script I have made does not work.

script.Parent.ClickDetector.MouseClick:connect(function(plr)
	if plr.Parent:FindFirstChild("Humanoid") then
	script.Parent.Parent:SetPrimaryPartCFrame(CFrame.new(10,1.5,10))
	plr.Parent.Torso.CFrame = script.Parent.Parent.Seat.CFrame
	end
end)

There are no errors in the output. Can anybody help?

2 answers

✓ Accepted answer

MouseClick passes the player who clicked the button as the first parameter. The problem in your script lies in line 2 and line 4: Player.Parent does NOT get you the Player's character model, so plr.Parent:FindFirstChild("Humanoid") will always be false. You're probably confounding this with BasePart's Touched event.

Solution

Players have a property called Character. You can do Player.Character to get the player's character model. Since you can be sure that only a player would click the button, you don't even have to check for a Humanoid.

script.Parent.ClickDetector.MouseClick:connect(function(plr)
    script.Parent.Parent:SetPrimaryPartCFrame(CFrame.new(10,1.5,10))
    plr.Character.Torso.CFrame = script.Parent.Parent.Seat.CFrame
end)

1 comment

0

Thanks a lot.

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