I have created this script and it works but it only works for like 2 times before it stops working. So i put the keycard in the detector and it scans red and i do it once more and scans red but on the third time or something it doesn't scan red??
Anyone know how to fix it.
The script:
db = false;
script.Parent.Touched:Connect(function(hit)
if not db then
if hit.Parent.name == "FAKEKeycard" then
db = true
if math.random(1,100) >= 40 then
db = false
print('Door Closed')
script.Parent.Parent.Light1.BrickColor = BrickColor.new("Bright red")
wait(0.5)
script.Parent.Parent.Light2.BrickColor = BrickColor.new("Bright red")
wait(0.5)
script.Parent.Parent.Light3.BrickColor = BrickColor.new("Bright red")
wait(1)
script.Parent.Parent.Light1.BrickColor = BrickColor.new("Institutional white")
script.Parent.Parent.Light2.BrickColor = BrickColor.new("Institutional white")
script.Parent.Parent.Light3.BrickColor = BrickColor.new("Institutional white")
end
end
end
end)

6 comments
What's the purpose of line 7?
you should plant a seed in the beginning of the script to get a more random result ( math.randomseed(tick()) ) it stops working because if the random number is less than 40 then db stays true
The percentage. So if the math.random is over 40 then the bricks go red.
How would i plant a seed in the script. I'm not sure how that works. I'm new to scripting.
just put math.randomseed(tick()) at line 1, move line 6 before line 5, and line 8 after line 23
Thanks so muchh