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

My gate is not working even though it was before. Anyone know how to fix the script?

Asked by 4 years ago

So, before my gate moved perfectly fast and smooth, but not it moves inch by inch very slow and very roughly. This is the code: Anybody know how to fix it?

local trigger = script.Parent
local gate = script.Parent.Parent.Gate

moving = false
open = false

function onClick()

    if open == false and moving == false then

        moving = true
        trigger.BrickColor = BrickColor.new("Bright yellow")

        for i = 1, (gate.Size.Y * 10 + 1) do
            wait()
            gate.CFrame = gate.CFrame*CFrame.new(0, 0.1, 0)
        end

        moving = false
        open = true
        trigger.BrickColor = BrickColor.new("Bright red")

    elseif open == true and moving == false then

        moving = true
        trigger.BrickColor = BrickColor.new("Bright yellow")

        for i = 1, (gate.Size.Y * 10 + 1) do
            wait()
            gate.CFrame = gate.CFrame*CFrame.new(0, -0.1, 0)
        end

        moving = false
        open = false
        trigger.BrickColor = BrickColor.new("Bright green")

    end

end

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


0
I tried this in one of my worlds I think it maybe the place itself is very slow or laggy because I tried the script and it seemed to move smoothly deth836231 142 — 4y
0
Ok satrasatra 8 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

I'd recommend using the tweening service over loops like this. It'll be much cleaner and more reliable.

Ad

Answer this question