So i am working a simulator game and i was working pretty well but then i hit a slump. This script works and all but when a person clicks and earn money the money wont show up for another player.
Here is the script:
local toolName = "AdvancedCard" -- what tool(name) must be held to earn?
local randomizeAmount = true -- randomize cash amount? if true, cash will be randomised, if false, cash will be the same everytime
local cashStatic = 1 --if 'randomizeAmount' is FALSE, how much money should be earned by 1 click?
local cashRandomX = 15 --if 'randomizeAmount' is TRUE, what is the MINimum cash amount?
local cashRandomY = 20 --if 'randomizeAmount' is TRUE, what is the MAXimum cash amount?
local debugging = true --debugging mode? if true, info will be print to the console, if false, script is not printing anything
local leaderstatName = "Cash" --name of Cash leaderstat
----------
local plr = game.Players.LocalPlayer
local equip = false
local mouse = plr:GetMouse()
plr.Backpack:WaitForChild(toolName).Equipped:Connect(function()
equip = true
end)
plr.Backpack:WaitForChild(toolName).Unequipped:Connect(function()
equip = false
end)
mouse.Button1Down:Connect(function()
if equip then
wait(0.5)
if randomizeAmount then
local amount = math.random(cashRandomX, cashRandomY)
plr.leaderstats:WaitForChild(leaderstatName).Value = plr.leaderstats:WaitForChild(leaderstatName).Value + amount
if debugging then
print("Player "..plr.Name.." just earned $"..amount.." for clicking with the tool.")
end
else
plr.leaderstats:WaitForChild(leaderstatName).Value = plr.leaderstats:WaitForChild(leaderstatName).Value + cashStatic
if debugging then
print("Player "..plr.Name.." just earned $"..cashStatic.." for clicking with the tool.")
end
end
end
end)
Please help me fix this.

2 comments
you need to use a remote event to change the "cash" value, it cant be changed from a localscript.
What he said, I have encountered this before