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

I FireServer number. Why scripts not working?

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

0

does += even work on roblox

0

cash = cash + num, use that

0

It does work, += was added recently.

0

I testing += and = it equally

1 answer

The 'num' is not a value, try checking it again, it may be part or you forgot to do num.Value

1 comment

0

can you send working script?

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