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

Why is my cframe rotating lid script not working?

Asked by 6 years ago

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)

1 answer

Log in to vote
1
Answered by 6 years ago

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)
0
Thanks dude! How would I fix the instance Pandora? crystalclay 70 — 6y
Ad

Answer this question