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

door script only expands and doesnt retract? [solved]

Asked by
RAFA1608 543 Moderation Voter
4 years ago
Edited by User#5423 4 years ago

so im making a door for my border game but the door script doesnt seem to work? well, it works, but the door ONLY expands down and doesnt retract. heres the script:

local gate = script.Parent
local button = gate.Parent["gate button"]
local clickdetector = button.ClickDetector
local debounce = false
local opened = false
clickdetector.MouseClick:Connect(function()
    if debounce then return end
    if opened == true then
        debounce = true
        for i = 16.5,0.5,0.25 do
            gate.Position = gate.Position - Vector3.new(0,0.125,0)
            gate.Size = gate.Size + Vector3.new(0,0.25,0)
        end
        opened = false
        debounce = false
    end
    if opened == false then
        debounce = true
        for i = 16.5,0.5,0.25 do
            wait(0.1)
            gate.Position = gate.Position + Vector3.new(0,0.125,0)
            gate.Size = gate.Size - Vector3.new(0,0.25,0)
        end
        opened = true
        debounce = false
    end
end)

thank you for your help :p

0
maybe add a wait(.1) when ur closing it HappyTimIsHim 652 — 4y
0
maybe add a wait(.1) when ur closing it HappyTimIsHim 652 — 4y
0
oh... i forgot to do that... hold on RAFA1608 543 — 4y
0
now it doesnt even work :/ RAFA1608 543 — 4y
0
add [Solved] to mark as self solved User#5423 17 — 4y

2 answers

Log in to vote
0
Answered by 4 years ago

Just use an else because it's a bool, it can only hold 2 values.

local gate = script.Parent
local button = gate.Parent["gate button"]
local clickdetector = button.ClickDetector
local debounce = false
local opened = false
clickdetector.MouseClick:Connect(function()
    if debounce then return end
    if opened == true then
        debounce = true
        for i = 16.5,0.5,0.25 do
            gate.Position = gate.Position - Vector3.new(0,0.125,0)
            gate.Size = gate.Size + Vector3.new(0,0.25,0)
        end
        opened = false
        debounce = false
    end
    else
        debounce = true
        for i = 16.5,0.5,0.25 do
            wait(0.1)
            gate.Position = gate.Position + Vector3.new(0,0.125,0)
            gate.Size = gate.Size - Vector3.new(0,0.25,0)
        end
        opened = true
        debounce = false
    end
end)

0
it didnt make a difference RAFA1608 543 — 4y
0
Is it local or server BradNewTypical 232 — 4y
0
its a server script RAFA1608 543 — 4y
0
maybe try doing the rot with remotes BradNewTypical 232 — 4y
Ad
Log in to vote
0
Answered by
RAFA1608 543 Moderation Voter
4 years ago

apparently the for loop was wrong :/ it didnt run because the for loop was already finished (startervalue was 16.5 and finish value was 0.5, so, technically it was more than finished?) fixed version:

local gate = script.Parent.Parent.Gate
local button = script.Parent
local clickdetector = script.Parent.ClickDetector
local debounce = false
local opened = false
clickdetector.MouseClick:Connect(function(plr)
    print("yease")
    if debounce == true then return end
    if opened == true then
        print("its opend but its now closing")
        debounce = true
        for XVI = 0.5,16.5,0.25 do
            wait(0.1)
            gate.Position = gate.Position - Vector3.new(0,0.125,0)
            gate.Size = gate.Size + Vector3.new(0,0.25,0)
        end
        opened = false
        debounce = false
    else
        print("its closd but its now opening")
        debounce = true
        for XVI = 0.5,16.5,0.25 do
            wait(0.1)
            gate.Position = gate.Position + Vector3.new(0,0.125,0)
            gate.Size = gate.Size - Vector3.new(0,0.25,0)
        end
        opened = true
        debounce = false
    end
end)
0
Wow i wrote up a whole answer saying this and then i refreshed. Using for i loops to open a door is not the best, tween service is much smoother and arguably easier to use iiConstable_Subwayx 130 — 4y
0
oh really? well, i dont know what a tween service is, but i might check it out later. Thank you. RAFA1608 543 — 4y

Answer this question