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

Made a Gate Remote (Why this dont work?)

Asked by
dekkeda 30
4 years ago
Edited 4 years ago

I've made a gate remote (Tool) opens barriers. However first two gates it works on but the latest one not.

script.Parent.Activated:Connect(function()
    local distance1 = (script.Parent.Handle.Position - workspace.Fence_Gate2.Model.Trigger.Position).magnitude
    local distance2 = (script.Parent.Handle.Position - workspace.Fence_Gate.Model.Trigger.Position).magnitude
    local distance3 = (script.Parent.Handle.Position - workspace.Fence_Gate3.Model.Trigger.Position).magnitude
    if distance1 < distance2 and distance3 then
        if distance1 <= 50 then
            game.Workspace.Fence_Gate2.Model.RFID1.LED.BrickColor = BrickColor.new("Lime green")
            game.Workspace.Fence_Gate2.Model.allowed.Value = true
            wait(5)
            game.Workspace.Fence_Gate2.Model.RFID1.LED.BrickColor = BrickColor.new("Bright orange")
            game.Workspace.Fence_Gate2.Model.allowed.Value = false
        end
        elseif distance2 < distance1 and distance3 then
            if distance2 <= 50 then
                game.Workspace.Fence_Gate.Model.RFID1.LED.BrickColor = BrickColor.new("Lime green")
                game.Workspace.Fence_Gate.Model.allowed.Value = true
                wait(5)
                game.Workspace.Fence_Gate.Model.RFID1.LED.BrickColor = BrickColor.new("Bright orange")
                game.Workspace.Fence_Gate.Model.allowed.Value = false
            end
        elseif distance3 < distance2 and distance1 then
                -- Code that doesnt work
                if distance3 <= 50 then
                    game.Workspace.Fence_Gate3.Model.RFID1.LED.BrickColor = BrickColor.new("Lime green")
                    game.Workspace.Fence_Gate3.Model.allowed.Value = true
                    wait(5)
                    game.Workspace.Fence_Gate3.Model.RFID1.LED.BrickColor = BrickColor.new("Bright orange")
                    game.Workspace.Fence_Gate3.Model.allowed.Value = false
                end
    end
end)

He doesnt reach the latest code.

Answer this question