I need help with a reward script

Hi I am new to scripting and have tried everything and still I am not able to. How can I make that with every win 20 points are added instead of copying all the time and pasting.

if Wins == 1 then
player.leaderstats.Points.Value = player.leaderstats.Points.Value = 20
end

if Wins == 2 then
player.leaderstats.Points.Value = player.leaderstats.Points.Value = 40
end

if Wins == 3 then
player.leaderstats.Points.Value = player.leaderstats.Points.Value = 60
end

3 Likes

With this code you have it every win you get 20 x how many wins you get. What you should do is make wins a Leaderstat called “Wins” and use this script (Put in StarterPlayer):


local leaderstats = script.Parent:WaitForChild("leaderstats")
local Points =  leaderstats:WaitForChild("Points")
local Wins =  leaderstats:WaitForChild("Wins")

currentwins = Wins.Value

Wins.Changed:Connect(function()
    if Wins.Value > currentwins then
        currentwins = Wins.Value
        Points.Value = Points.Value + 20
    end
end)
5 Likes

attempt to index number with ‘changed’

1 Like

and I don’t have wins as leaderstats.
Local wins = player:Loadnumber(“survives”)

1 Like

LoadNumber is deprecated and should not be used.

1 Like

How come you did not put Wins in the leaderstats container? Besides, do not use :LoadNumber(). This has been deprecated in favor of Datastores.

Please use an IntValue or a NumberValue and put it in leaderstats for this to work.

1 Like

Yeah it would need to be a Int Value for it to work.

1 Like

If I do it as intvalue or numbervalue then my other script doesn’t work anymore is there another solution?

1 Like

And I don’t want wins to be in leaderstats.

1 Like
wins
if Wins == Wins + 1 then
player.leaderstats.Points.Value = player.leaderstats.Points.Value + 20
end

This should work, give it a go.

2 Likes