Hi. If there’s any way on optimizing the following script, please let me know.
I’m trying to make a script that automatically destroys a door when a player joins if the player has the right amount of kills. I know you can sorta use v in pairs but I haven’t gotten there yet.
local Players = game:GetService("Players")
local plr = Players.LocalPlayer
local doors = workspace:WaitForChild("Doors")
if doors then
if plr.leaderstats.Kills.Value >= 75 then
doors.Door1:Destroy()
if plr.leaderstats.Kills.Value >= 150 then
doors.Door2:Destroy()
if plr.leaderstats.Kills.Value >= 350 then
doors.Door3:Destroy()
if plr.leaderstats.Kills.Value >= 550 then
doors.Door4:Destroy()
if plr.leaderstats.Kills.Value >= 750 then
doors.Door5:Destroy()
if plr.leaderstats.Kills.Value >= 1000 then
doors.Door6:Destroy()
if plr.leaderstats.Kills.Value >= 1250 then
doors.Door7:Destroy()
if plr.leaderstats.Kills.Value >= 1500 then
task.wait(1.5) --This door always starts the chain of errors.
doors:WaitForChild("Door8"):Destroy()
if plr.leaderstats.Kills.Value >= 2000 then
doors:WaitForChild("Door9"):Destroy()
if plr.leaderstats.Kills.Value >= 2750 then
doors:WaitForChild("Door10"):Destroy()
if plr.leaderstats.Kills.Value >= 3250 then
doors:WaitForChild("Door11"):Destroy()
if plr.leaderstats.Kills.Value >= 3750 then
doors:WaitForChild("Door12"):Destroy()
if plr.leaderstats.Kills.Value >= 4250 then
doors:WaitForChild("Door13"):Destroy()
if plr.leaderstats.Kills.Value >= 4750 then
doors:WaitForChild("Door14"):Destroy()
if plr.leaderstats.Kills.Value >= 5250 then
doors:WaitForChild("Door15"):Destroy()
if plr.leaderstats.Kills.Value >= 6250 then
doors:WaitForChild("Door16"):Destroy()
if plr.leaderstats.Kills.Value >= 7550 then
doors:WaitForChild("Door17"):Destroy()
if plr.leaderstats.Kills.Value >= 8250 then
doors:WaitForChild("Door18"):Destroy()
if plr.leaderstats.Kills.Value >= 9250 then
doors:WaitForChild("Door19"):Destroy()
if plr.leaderstats.Kills.Value >= 10250 then
doors:WaitForChild("Door20"):Destroy()
if plr.leaderstats.Kills.Value >= 11750 then
doors:WaitForChild("Door21"):Destroy()
if plr.leaderstats.Kills.Value >= 13250 then
doors:WaitForChild("Door22"):Destroy()
if plr.leaderstats.Kills.Value >= 15750 then
doors:WaitForChild("Door23"):Destroy()
if plr.leaderstats.Kills.Value >= 17250 then
doors:WaitForChild("Door24"):Destroy()
if plr.leaderstats.Kills.Value >= 20750 then
doors:WaitForChild("Door25"):Destroy()
if plr.leaderstats.Kills.Value >= 22750 then
doors:WaitForChild("Door26"):Destroy()
if plr.leaderstats.Kills.Value >= 24750 then
doors:WaitForChild("Door27"):Destroy()
if plr.leaderstats.Kills.Value >= 26750 then
doors:WaitForChild("Door28"):Destroy()
if plr.leaderstats.Kills.Value >= 28750 then
doors:WaitForChild("Door29"):Destroy()
if plr.leaderstats.Kills.Value >= 30750 then
doors:WaitForChild("Door30"):Destroy()
if plr.leaderstats.Kills.Value >= 35750 then
doors:WaitForChild("Door31"):Destroy()
if plr.leaderstats.Kills.Value >= 40750 then
doors:WaitForChild("Door32"):Destroy()
if plr.leaderstats.Kills.Value >= 50750 then
doors:WaitForChild("Door33"):Destroy()
if plr.leaderstats.Kills.Value >= 60750 then
doors:WaitForChild("Door34"):Destroy()
if plr.leaderstats.Kills.Value >= 70750 then
doors:WaitForChild("Door35"):Destroy()
if plr.leaderstats.Kills.Value >= 80750 then
doors:WaitForChild("Door36"):Destroy()
if plr.leaderstats.Kills.Value >= 95750 then
doors:WaitForChild("Door37"):Destroy()
if plr.leaderstats.Kills.Value >= 110750 then
doors:WaitForChild("Door38"):Destroy()
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end