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

What is wrong with this script?

Asked by 10 years ago

I want it so my door SLIDES to the right (when you are facing the door) and when you click it again, it slides back, click it again slides to the right and so on. However, my script makes my door rotate 90 degrees then breaks. It does not rotate back when you click it again. Here is my script

local brick = script.Parent.brick
local c = true

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

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

brick.ClickDetector.MouseClick:connect(OnC)

What is wrong with it?

1 answer

Log in to vote
0
Answered by
lomo0987 250 Moderation Voter
10 years ago
local brick = script.Parent.brick
local c = true

function OnC()
    if c == true then
        c = false
        brick.CFrame = CFrame.new(-39.2, 4.69, -53.3)
-- the end was here, it shouldn't have been.        


    elseif c == false then -- changed this to elseif
        c = true
        brick.CFrame = CFrame.new(-39.2, 4.69, -46.8)
    end
end

brick.ClickDetector.MouseClick:connect(OnC)

What was wrong is that you had an end.. and you didn't do an elseif.. So it only processed the first part.

Ad

Answer this question