Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

how do i fix this keycard script that only works 2 times?

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

0

What's the purpose of line 7?

0

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

0

The percentage. So if the math.random is over 40 then the bricks go red.

0

How would i plant a seed in the script. I'm not sure how that works. I'm new to scripting.

0

just put math.randomseed(tick()) at line 1, move line 6 before line 5, and line 8 after line 23

0

Thanks so muchh

1 answer

✓ Accepted answer

I think it might have been answered in the comments, but you haven't removed it, so here:

It could be due to the fact that 60% of the time, the door is closed and you can't get in. The other 40%, it leaves db as true, so the script won't run after it reaches line 4. Maybe?

1 comment

0

And 4 months later, it was accepted.

This discussion is preserved as it was. New answers, comments, and votes are closed.