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

Why won't this script work?

My script doesn't seem to work properly.

brick = script.Parent.brick
c = true

function OnC()
	if c == true then
		c = false
		brick.CFrame = CFrame.new(-39.2, 4.69, -53.3)
	else
		brick.CFrame = CFrame.new(-39.2, 4.69, -46.8)
		c = false
		
	end
end

brick.ClickDetector.MouseClick:connect(OnC)

When I click my door, it rotates 90 degrees. When I click it again, it goes back. When I attempt to click one last time, it does not do anything. The script breaks after that.

2 answers

I see one error that I think is wrong. Since 'c' is acting as a debounce at the end you forgot to change it back to true. So line 10 should be like this:

c = true 
brick = script.Parent.brick
c = true
b = 0
function OnC()
    if c == true then
     brick.CFrame = CFrame.new(-39.2, 4.69, -53.3)
b = 1
c = false
end

if b == 1 then
        brick.CFrame = CFrame.new(-39.2, 4.69, -46.8)

c = true
b = 0
  end

    
end

brick.ClickDetector.MouseClick:connect(OnC)

2 comments

0

What exactly does "b = 0" mean?

0

Variable should work.

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