How can I make this proximity prompt give a random amount of money?

I tried doing math.random, but couldn’t seem to figure it out. Any help is greatly appreciated. I’m trying to make it so you either get a big amount or a small amount.

local Prompt = script.Parent
Prompt.Triggered:Connect(function(Player)
	local Money = Player.leaderstats.Money
	Money.Value += 7
end)

I’d recommend reading this for help

But I always disliked people who just pasted the link and never actually helped

First of all, is it in a localscript? Because if so, you can modify the player’s leaderstats, however they will appear exclusively for the player and get overwritten when the server changes a value.

And second, to add a random value of money, you could do Money.Value += math.Random(1,[Whatever you want the highest amount of money possible to get]).

1 Like

Try this:

local Prompt = script.Parent
Prompt.Triggered:Connect(function(Player)
    local cash=math.random(100,1000)
    if Player:FindFirstChild("leaderstats") then
	   local Money = Player.leaderstats.Money
	   Money.Value += cash
    end
end)
1 Like

I’d suggest reading this also,

You could just take his script but I’d recommend getting a good understanding of it also.

2 Likes

As @DyzuOfficial mentioned its better off if you get a gist of basic luau as knowing the basics will give you a broader depth of knowledge on how to implement them in a practical example when utilizing objects such as the proximity prompt to perform a special effect or grant rewards,etcc.

3 Likes

If you’re looking for a 50/50 chance for a bigger or smaller amount, you can do as following:

local Prompt = script.Parent

local function onTriggered(Player)
	local money = 3
	if Player:FindFirstChild("leaderstats") then
		local StatValue = Player.leaderstats.Money
		if math.round(math.random(0,1)) == 1 then -- Will either equate to 0, or 1
			money = 7
		end
		StatValue.Value += money
	end
end

Prompt.Triggered:Connect(onTriggered)

You could also replace

if math.round(math.random(0,1)) == 1 then
	  money = 7
end
-- with
math.round(math.random(3,7)) * 100 -- 300 to 700, customise to your hearts content!
2 Likes

Thank you so much, I definitely will take a deeper dive. I have been trying my best to learn and understand more coding. I just seem to always have the trouble of grasping of where to put the lines and stuff, but thank you again,

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.