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

How do I fix Money leaderboard when i spend it?

Okay so, I was working on a Roblox Shop project I created a Leaderboard with money stats Players start with 125 coins and they get 25 coins every 15 seconds. But when someone buys a Bloxy Cola for 50 coins, when they get their 25 coins. The coins restore.

This is the proof video

This is the Shop Script

This is the Leaderboard script

Thanks for taking time to read.

I am learning to script and I started 2 weeks ago I watched some YT videos to make these.

1 answer

✓ Accepted answer

You have the right idea, the only issue with this is that you are changing the value of your money inside a local script. The reason why this doesn't work is due to Filtering Enabled. This property prevents exploiters from altering world properties server-wide, thus, in order to change your money value, you would have to change it from a server script. I see you have a remote event fired to the server with "tool.Value", I'm assuming this is to replicate the tool inside the player backpack!

From that local script, remove the eighth line and fire the server with two values, the tool.Value and the price. That way, these values can be picked up from the server script and be manipulated server-wide.

Here's what the local script should look like now:

local price = script.Parent.Parent.Price
local tool = script.Parent.Parent.ItemName
local plr = game.Players.LocalPlayer
    --Note, I don't see why you need "tools"

script.Parent.MouseButton1Click:connect(function()
    local ls = players:FindFirstChild("leaderstats")
    if ls and ls.LCoins.Value >= price.VAlue then 
	--If there's a leaderstats in the player and the Coin Value is greater than or equal to the price
		
		game.ReplicatedStorage.ShopBuy:FireServer(tool.Value, price.Value)
	end
end)

So, this sends the server the tool Value and the price of the tool. Now all we have to do is Replicate the tool into the backpack and change the cash values!

In the Server Script, you should have something similar to this:

local tools = game.ReplicatedStorage:WaitForChild("Tools")

game.ReplicatedStorage.ShopBuy.OnServerEvent:connect(function(plr, toolValue, price)
    --Your code to replicate tool into backpack goes here!

	local ls = plr:FindFirstChild("leaderstats") 
	if ls then
		ls.LCoins.Value = ls.LCoins.Value - price
	end
end)

So you input your tool-giving code in there, and while doing that, removing the price Value from the money value!

I hope this helps! LMK if you have any questions :)

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