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

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

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

✓ Accepted answer

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)

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