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

Can you help with my script? Add random value to leaderstats when click part.

Asked by 3 years ago

this script is not working and can someone please explain why? Because when I changed (randomnumber) to 1, it added one match to the leaderstats, so the problem is in a random number

local randomnumber = math.random(1,6)

script.Parent.ClickDetector.MouseClick:Connect(function(ply)
    ply.leaderstats.Matches.Value = ply.leaderstats.Matches.Value + (randomnumber)

end)

1 answer

Log in to vote
0
Answered by
jundell 106
3 years ago

Your problem is that you generate the random number once to add it to a variable. In order to fix this, simply just add the variable inside the MouseClick so it generates a new one each time.

script.Parent.ClickDetector.MouseClick:Connect(function(ply)
    local randomnumber = math.random(1,6)
    ply.leaderstats.Matches.Value = ply.leaderstats.Matches.Value + (randomnumber)
end)
Ad

Answer this question