I'm trying to get a debounce to work on this. I want it so you can only open the gate when the gate is closed and only close it when it is open.

I fixed it:

local trainerRank = 255
local groupId = 2645129

local isOpen = false

function onSpeakDo(message)
	if message:sub(1, 6) == ":open " then
		if not isOpen then
			print("Open")
			if game.Workspace:findFirstChild(message:sub(7)) then
				local Door = game.Workspace:findFirstChild(message:sub(7))

				local Top = Door:findFirstChild("Top")
				Top.PrimaryPart = Top.Main
				local TopStart = Top:GetPrimaryPartCFrame()

				local Bottom = Door:findFirstChild("Bottom")
				Bottom.PrimaryPart = Bottom.Main
				local BottomStart = Bottom:GetPrimaryPartCFrame()

				for i = 1, 100 do
				Top:SetPrimaryPartCFrame(TopStart:lerp(TopStart + Vector3.new(0, Top.Main.Size.Y, 0), i / 100))
				Bottom:SetPrimaryPartCFrame(BottomStart:lerp(BottomStart - Vector3.new(0, Bottom.Main.Size.Y, 0), i / 100))
				wait()
				end
				
				wait(3)
				isOpen = true
			end
		end
	end

	if message:sub(1, 7) == ":close " then
		if isOpen then
			print("Close")
			if game.Workspace:findFirstChild(message:sub(8)) then
				local Door = game.Workspace:findFirstChild(message:sub(8))

				local Top = Door:findFirstChild("Top")
				Top.PrimaryPart = Top.Main
				local TopStart = Top:GetPrimaryPartCFrame()

				local Bottom = Door:findFirstChild("Bottom")
				Bottom.PrimaryPart = Bottom.Main
				local BottomStart = Bottom:GetPrimaryPartCFrame()

				for i = 1, 100 do
				Top:SetPrimaryPartCFrame(TopStart:lerp(TopStart - Vector3.new(0, Top.Main.Size.Y, 0), i / 100))
				Bottom:SetPrimaryPartCFrame(BottomStart:lerp(BottomStart + Vector3.new(0, Bottom.Main.Size.Y, 0), i / 100))
				wait()
				end

				wait(3)
				isOpen = false
			end
		end
	end
end
						
game.Players.PlayerAdded:connect(function(newPlayer)
	for key, value in next, game:GetService("GroupService"):GetGroupInfoAsync(groupId).Roles do
		if value.Name:lower() == "champion" then
			trainerRank = value.Rank
		end
	end
	if newPlayer:GetRankInGroup(groupId) >= trainerRank  or newPlayer.Name == "bosswalrus" then
		newPlayer.Chatted:connect(onSpeakDo)
	end
end)

4 comments

1

Try to swap IsOpen values in lines 26 and 50

0

You're saying IsOpen in the open command is false on line 26, which is preventing the door from closing because of the if then statement on line 32. You also have IsOpen change to true at line 50 which will keep you from opening it again. Short terms, lines 26 and 50 change false to true and true to false.

1

It let's it open and close, but it let's it close whenever you want.

1

Fixed.