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)