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?
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)
The plr
argument passed is a Player, which means it doesn't have a Humanoid
in 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