I have made a random generator to make a red or green block appear but it won't show the block or always is Red and it's not changing no matter how many time's I click it. Here is my **Script **
local RN = math.random (1, 2) local GB = script.Parent.GreenButton local RB = script.Parent.RedButton GB.ProximityPrompt.Triggered:Connect(function() if RN == 2 then script.Parent.RedBlock.Transparency = 0 GB.ProximityPrompt.Archivable = false wait(5) script.Parent.RedBlock.Transparency = 1 GB.ProximityPrompt.Archivable = true end end) RB.ProximityPrompt.Triggered:Connect(function() if RN == 2 then script.Parent.RedBlock.Transparency = 0 GB.ProximityPrompt.Archivable = false wait(5) script.Parent.RedBlock.Transparency = 1 GB.ProximityPrompt.Archivable = true end end) GB.ProximityPrompt.Triggered:Connect(function() if RN == 1 then script.Parent.RedBlock.Transparency = 0 GB.ProximityPrompt.Archivable = false wait(5) script.Parent.RedBlock.Transparency = 1 GB.ProximityPrompt.Archivable = true end end) RB.ProximityPrompt.Triggered:Connect(function() if RN == 2 then script.Parent.RedBlock.Transparency = 0 GB.ProximityPrompt.Archivable = false wait(5) script.Parent.RedBlock.Transparency = 1 GB.ProximityPrompt.Archivable = true end end)
The red block appears because you only reference the red block in your code, not the green block.
I also would combine the seperate if
statements into a shorter if elseif
to make your code shorter, and make the RN re-define every time so it's actually randomised.
local RN = 0 local GB = script.Parent.GreenButton local RB = script.Parent.RedButton GB.ProximityPrompt.Triggered:Connect(function() RN = math.random(1, 2) if RN == 2 then script.Parent.GreenBlock.Transparency = 0 GB.ProximityPrompt.Archivable = false wait(5) script.Parent.GreenBlock.Transparency = 1 GB.ProximityPrompt.Archivable = true end end) RB.ProximityPrompt.Triggered:Connect(function() RN = math.random(1, 2) if RN == 1 then script.Parent.RedBlock.Transparency = 0 GB.ProximityPrompt.Archivable = false wait(5) script.Parent.RedBlock.Transparency = 1 GB.ProximityPrompt.Archivable = true end end)
Hope this helps.