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

Simple CFrame movement script not working?

Asked by
JJ_B 250 Moderation Voter
8 years ago

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

Log in to vote
1
Answered by
XAXA 1569 Moderation Voter
8 years ago

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)
0
Thanks a lot. JJ_B 250 — 8y
Ad
Log in to vote
1
Answered by
Gamenew09 180
8 years ago

The plrargument passed is a Player, which means it doesn't have a Humanoidin the Player. So what you would have to do is change all the references to the character like plr.Parent.Torso, to plr.Character.Torso.

http://wiki.roblox.com/index.php?title=API:Class/ClickDetector/MouseClick

Answer this question