Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

The random button press script doesn't work and I see no isuess any help?

Asked by 3 years ago

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)

1 answer

Log in to vote
0
Answered by 3 years ago

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.

0
now it's just picking the color I pick I wan't it to be random Blueturtle8908 79 — 3y
Ad

Answer this question