I created two script first in ServerScriptService, second in tool first script:
RS = game:GetService("ReplicatedStorage")
EE = RS:WaitForChild("EatEvent")
DSS = game:GetService("DataStoreService")
CS = DSS:GetDataStore("CashSave")
local function onPlayerJoin(plr)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
local gold = Instance.new("IntValue")
gold.Name = "Cash"
gold.Value = CS:GetAsync("Player_".. plr.UserId) or 0
gold.Parent = leaderstats
leaderstats.Parent = plr
end
game.Players.PlayerAdded:Connect(onPlayerJoin)
EE.OnServerEvent:Connect(function(plr, num)
local Cash = plr.leaderstats:WaitForChild("Cash").Value
Cash += num
end)
game.Players.PlayerRemoving:Connect(function(plr)
CS:SetAsync("Player_".. plr.UserId,plr.leaderstats.Cash.Value)
end)
second script:
tool = script.Parent.Parent
RS = game:GetService("ReplicatedStorage")
EE = RS:WaitForChild("EatEvent")
LocalPlayer = game.Players.LocalPlayer
val = script:WaitForChild("FoodInt")
tool.Activated:Connect(function()
EE:FireServer(LocalPlayer, val)
end)
Error: ServerScriptService.Script:17: attempt to perform arithmetic (add) on number and Instance

4 comments
does += even work on roblox
cash = cash + num, use that
It does work, += was added recently.
I testing += and = it equally