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

Why is my cframe rotating lid script not working?

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 '' 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

✓ Accepted answer

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)

1 comment

0

Thanks dude! How would I fix the instance Pandora?

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