Hello, I want my gate to open to a certain person with a button click and to close again after another click. It opens, but it doesn't close. Thanks for your help! PinoRisi03
Here's my code:
local opened = false local Door = script.Parent.Parent.Parent.Door local AllowedPlayers = {402603503, 1} --- allowed Players script.Parent.MouseClick:Connect(function(Player) local FoundInTable = false for _, userid in pairs(AllowedPlayers) do if Player.UserId == userid and FoundInTable == false then FoundInTable = true end end if FoundInTable == true then if opened == false then opened = true for i = 1,50 do Door.CFrame = Door.CFrame + Vector3.new(0,0,0.22) wait() end end else opened = false for i = 1,50 do Door.CFrame = Door.CFrame - Vector3.new(0,0,0.22) wait() end end end end) end
I think you have confused the if statements. Try this. It may work:
local opened = false local Door = script.Parent.Parent.Parent.Door local AllowedPlayers = {402603503, 1} --- allowed Players script.Parent.MouseClick:Connect(function(Player) local FoundInTable = false for _, userid in pairs(AllowedPlayers) do if Player.UserId == userid and FoundInTable == false then FoundInTable = true end end if FoundInTable == true then if opened == false then opened = true for i = 1,50 do Door.CFrame = Door.CFrame + Vector3.new(0,0,0.22) wait() end else opened = false for i = 1,50 do Door.CFrame = Door.CFrame - Vector3.new(0,0,0.22) wait() end end end end end) end