Hello. I have three forcefield doors and one of these scripts are in each of them. When I play the game and use the forcefields the game turns really laggy. I'm not really sure what the issue is, but it could just be an easy fix. Here is the script i'm using:
local door = script.Parent
local Republic = game.Teams.Republic
local RI = game.Teams.RI
local BlueTeam = game.Teams["501st"]
local CG = game.Teams["Coruscant Guard"]
local RG = game.Teams["Red Guard"]
local RC = game.Teams.Commandos
door.Touched:Connect(function(hit)
local humanoid = hit.Parent:FindFirstChild("Humanoid")
if humanoid then
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
if plr.Team == Republic then
door.CanCollide = false
door.Transparency = .5
wait(1)
door.CanCollide = true
door.Transparency = 0
elseif plr.Team == RI then
door.CanCollide = false
door.Transparency = .5
wait(1)
door.CanCollide = true
door.Transparency = 0
elseif plr.Team == BlueTeam then
door.CanCollide = false
door.Transparency = .5
wait(1)
door.CanCollide = true
door.Transparency = 0
elseif plr.Team == CG then
door.CanCollide = false
door.Transparency = .5
wait(1)
door.CanCollide = true
door.Transparency = 0
elseif plr.Team == RG then
door.CanCollide = false
door.Transparency = .5
wait(1)
door.CanCollide = true
door.Transparency = 0
elseif plr.Team == RC then
door.CanCollide = false
door.Transparency = .5
wait(1)
door.CanCollide = true
door.Transparency = 0
end
end
end)
If you could help me fix this problem I would be very happy. Thank you.

4 comments
Possibly add a debug variable?
This may seem like i'm dumb, but I am new to scripting. How would I add a debug variable?
Wait sorry I meant debounce. Basically add a local variable that stops the script from running more than once at a time which happens a lot to touched events.
At line 08 lets say "local Debounce = false" and at the start of the event add "if Debounce == true then return end", the next line should turn Debounce to true and the last line of the function should have a small wait after which then turns Debounce back to false.