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

door script only expands and doesnt retract? [solved]

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

5 comments

0

maybe add a wait(.1) when ur closing it

0

maybe add a wait(.1) when ur closing it

0

oh... i forgot to do that... hold on

0

now it doesnt even work :/

0

add [Solved] to mark as self solved

2 answers

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)

4 comments

0

it didnt make a difference

0

Is it local or server

0

its a server script

0

maybe try doing the rot with remotes

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)

2 comments

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

0

oh really? well, i dont know what a tween service is, but i might check it out later. Thank you.

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