Certain chance to give the player money

I’m wanting to make is so that every time my NPC goes to point B, there is a chance a random amount of cash ranging from 1-100 is added to the players leaderstat.

I will do this later, but I will also be making a shop system where if you buy something it will increase the chance of you receiving cash and/or receiving more cash. So I want to ensure my code is flexible.

I’m not sure how I can go about this as I’m not very good with things regarding leaderstats, so I would just like any form of assistance.

Here is my code:

local h = script.Parent

local a = workspace.WalkParts.a

local b = workspace.WalkParts.b

local c = workspace.WalkParts.c

while true do
	h:MoveTo(a.Position)
	wait(10)
	h:MoveTo(b.Position)
	--Assuming I add the code here
	wait(5)
	h:MoveTo(c.Position)
	wait(10)
end

If something doesn’t make sense, please let me know, thank you!

You would want to do this

local RandomCashAmount = math.random(1,100)
PathToCashHere.Value += RandomCashAmount
1 Like

Thank you for the help,

But I’m not sure how I can find the leaderstat in the server script for “PathToCashHere.Value”

You’ll need a datastore script, and then find the player in Players and get the leaderstats from there.

1 Like

@NebulaV5
I was about to type this but it was solved, it also wasnt what the topic was about.

wait()

Player = game.Players:GetPlayers()

playerPicked = Player[math.random(1,#Player)]

wait(1)

print(playerPicked)

You might be able to use this to find a random player for the random cash

1 Like