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

click detector and math random?

Asked by
Owca_S 0
4 years ago
Edited 4 years ago

i tried to make when player click on brick then math.random then brick changing color, but it not works

script.Parent.MouseClick:Connect(function()

local number = math.random(1, 2)  
number = math.random(1, 2)
print(number)
    if math == 1 then   
    print("1")  
script.Parent.Parent.BrickColor = BrickColor.Random()
    if math == 2 then   
script.Parent.Parent.BrickColor = BrickColor.Random()
    print("2")
end
end
        end)

2 answers

Log in to vote
0
Answered by 4 years ago

Maybe switching out the if math to if number will work + i added "elseif" so if the number isnt 1 it will do number 2

script.Parent.MouseClick:Connect(function()

local number = math.random(1, 2)  
number = math.random(1, 2)
print(number)
    if number == 1 then   
    print("1")  
script.Parent.Parent.BrickColor = BrickColor.Random()
    elseif number == 2 then   
script.Parent.Parent.BrickColor = BrickColor.Random()
    print("2")
end
end
        end)

If this doesn't work try to keep the "elseif" and switch back to "if math" instead of "if number"

Hopefully this works/helps!

0
No need to define number twice ForeverBrown 356 — 4y
0
There's no need for number at all if you're just going to use BrickColor.Random() on the same part. It doesnt make it extra random XD EmilyBendsSpace 1025 — 4y
Ad
Log in to vote
0
Answered by
Xapelize 2658 Moderation Voter Community Moderator
4 years ago

You can delete that math.random. Because the number was 1 or 2 same to random brick color.

script.Parent.MouseClick:Connect(function() -- fire the MouseClick Event

function OnClicked() -- when clicked
    script.Parent.Parent.BrickColor = BrickColor.Random() -- Random brickColor
    print(math.random(1, 2) -- print 1 or 2
end) -- end (if you end a function then you need to use 'end)' )

script.Parent.MouseClick:Connect(function(OnClicked) -- when clicked fire the OnClicked function

Answer this question