So basically, I am trying to make a treasure box which flips open if you click on it. Why is it not working? The lid rotates around a hinge on the end of the box.
Here are the error messages in output I am receiving:
20:36:48.733 - Workspace.Pandora.Spin:14: 'end' expected (to close 'function' at line 1) near '<eof>' 20:36:48.734 - ClickDetector is not a valid member of Model
Other info:
First I tried storing it in server script storage, then in the box's model itself.
function onClicked(PlayerWhoClicked) local lid = workspace:WaitForChild("Lid") local hinge = workspace:WaitForChild("Hinge") local hingePos = hinge.Position for i = 1,180 do lid.CFrame = CFrame.new(hingePos)* CFrame.Angles(0,math.rad(i),0) * CFrame.new (3,0,0) wait() end workspace.Pandora.ClickDetector.MouseClick:connect(onClicked)
Hi!
You need to put an extra "end" to close both the funtion and for do loop. Also, double check if you are redirecting whatever the click part is correctly. Based on the error, the instance "Pandora" inside the workspace is a model, which are not operable for ClickDetectors. Be sure to fix that.
function onClicked(PlayerWhoClicked) local lid = workspace:WaitForChild("Lid") local hinge = workspace:WaitForChild("Hinge") local hingePos = hinge.Position for i = 1,180 do lid.CFrame = CFrame.new(hingePos)* CFrame.Angles(0,math.rad(i),0) * CFrame.new (3,0,0) wait() end end workspace.Pandora.ClickDetector.MouseClick:connect(onClicked)