I Tweened a Vertical door. That opens once a player hits the button, and the button should turn green once the door is open, then once pressed again the door closes and the button turns back to red.
My problem is that when I press the button the door doesn’t open the first time I have to double click it then the button turns green, but doesn’t change again. I tried using a debounce and it still does the same thing.
To summarize: When I press the button it doesn’t open until I double click it and the button turns green once and it doesn’t turn back to red once the door closes.
My script
Door = script.Parent.Parent:WaitForChild("door")
local TweenService = game:GetService("TweenService")
local tweeninginformation = TweenInfo.new(
2,
Enum.EasingStyle.Linear,
Enum.EasingDirection.Out,
0,
false,
0
)
local dooropen = {CFrame = CFrame.new(32.981, 58.462, 118.421)}
local doorclose = {CFrame = CFrame.new(32.981, 20.12, 118.421)}
local tweenopen = TweenService:Create(Door,tweeninginformation,dooropen)
local tweenclose = TweenService:Create(Door,tweeninginformation,doorclose)
local ClickDetector = script.Parent.ClickDetector
local Debounce = false
ClickDetector.MouseClick:Connect(function(Player)
if Player:GetRankInGroup(5221697) >= 6 and not Debounce then
script.Parent.BrickColor = BrickColor.new("Lime green")
tweenopen:Play()
end
if Player:GetRankInGroup(5221697) >= 6 and not Debounce then
tweenclose:Play()
script.Parent.BrickColor = BrickColor.new("Really red")
end
Debounce = false
script.Parent.BrickColor = BrickColor.new("Lime green")
end)
EDIT: It seems I have solved it by changing the way my debounce works, thanks for all your help guys.
Door = script.Parent.Parent:WaitForChild("door")
local TweenService = game:GetService("TweenService")
local tweeninginformation = TweenInfo.new(
2,
Enum.EasingStyle.Linear,
Enum.EasingDirection.Out,
0,
false,
0
)
local dooropen = {CFrame = CFrame.new(32.981, 58.462, 118.421)}
local doorclose = {CFrame = CFrame.new(32.981, 20.12, 118.421)}
local tweenopen = TweenService:Create(Door,tweeninginformation,dooropen)
local tweenclose = TweenService:Create(Door,tweeninginformation,doorclose)
local ClickDetector = script.Parent.ClickDetector
ClickDetector.MouseClick:Connect(function(Player)
if Player:GetRankInGroup(5221697) >= 6 and not Debounce then
tweenopen:Play()
script.Parent.BrickColor = BrickColor.new("Lime green")
end
if Player:GetRankInGroup(5221697) >= 6 then
tweenclose:Play()
script.Parent.BrickColor = BrickColor.new("Really red")
end
end)
I don’t know if this will work, but I removed the end after tweenclose and put it after the brickcolour change