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

Why didn't it position after I onClicked it?

I hit the lid, and it didn't like put it in the position I wanted it to be. This is what the script is:

local lid = game.Workspace.BoxCD.Lid
sound = Instance.new("Sound")

function onClicked()
	if onClicked(lid) then
		lid.CFrame = CFrame.new(9.445, lid.CFrame.Y, lid.CFrame.Z)
		wait(0.1)
		lid.CFrame = CFrame.new(8.205, lid.CFrame.Y, lid.CFrame.Z)
	end
end

script.Parent.ClickDetector.MouseClick:connect(onClicked)

2 comments

3

You're expecting a function call to return a true or false value to a if then statement that does not return one. Is this script parented to 'lid'?

0

Oh okay. Thanks M39

1 answer

Sorry if I didn't understand the script. You stated the problem, but you didn't say what you intended the script to do.

In my script, when you click script.Parent.ClickDetector, it makes the lid switch between the two positions of Cframe.X = 8.205 and Cframe.X = 9.445.

local lid = game.Workspace.BoxCD.Lid
local sound = Instance.new("Sound")
local jammed = false
function onClicked() --fires each time the button is clicked
    if not jammed then
	jammed = true
        lid.CFrame = CFrame.new( ((lid.CFrame.X == 8.205) and 9.445 or 8.205), lid.CFrame.Y, lid.CFrame.Z)
        wait(0.1)
        jammed = false
    end
end

script.Parent.ClickDetector.MouseClick:connect(onClicked)

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