I get attempt to perform arithmetic (add) on number and Instance

Hello,

I am making a system that gives the player money but the output says:

attempt to perform arithmetic (add) on number and Instance

I am using a local script in StarterGui and a server script in ServerScriptService.

Local script
print("Hello world")
local secLabel = script.Parent:WaitForChild("Sec")
local minLabel = script.Parent:WaitForChild("Min")
local seconds = 1
local minutes = 0
local on = false
local wasOn = false
local earn = 5
local earnings = 0
local moneyFrame = script.Parent.Parent:WaitForChild("Earnings")

local player = game.Players.LocalPlayer

local part = workspace.Pizza:WaitForChild("CustomerChoose")

local character = player.Character
local humanoid = character:WaitForChild("Humanoid")

--local part  = game.Workspace.Pizza.Part
local distance = (character.HumanoidRootPart.Position - part.Position).magnitude
local maxD = 10

local function stopTimer()
	seconds = 1
	minutes = 0
	secLabel.Parent.Visible = false
	moneyFrame.Visible = false
	game.ReplicatedStorage.GiveMoney:FireServer(player, earnings)
	earnings = 0
end

local function timerForPizza()
	
	repeat
		
		seconds += 1
		secLabel.Parent.Visible = true
		moneyFrame.Visible = true
		if seconds >= 60 then
			minutes += 1
			seconds = 0
			earnings += earn
			
		end
		secLabel.Text = tostring(seconds)
		minLabel.Text = tostring(minutes)
		
		--player.Jobs.Earn.Value += earn--Change this to the player leader stats
		moneyFrame.earn.Text = tostring(earnings)
		wait(0.5)
	until on == false


end

while wait(1) do
	if (character.HumanoidRootPart.Position - part.Position).magnitude < maxD then
		timerForPizza()
		print("Yay")
		if wasOn then
			seconds = 1
			minutes = 0
			wasOn = false
			secLabel.Parent.Visible = true
		end
	else
		print("No")
		stopTimer()
		wasOn = true
		game.ReplicatedStorage.GiveMoney:FireServer(player)
	end
end
--script.Parent.TextButton.MouseButton1Click:Connect(function()
--on = true
--timerForPizza()
--end)

Here is the line the line that fires the event:
game.ReplicatedStorage.GiveMoney:FireServer(player, earnings)

And here is the server script:
local player = game.Players.LocalPlayer

game.ReplicatedStorage.GiveMoney.OnServerEvent:Connect(function(player, earnings)

player.leaderstats.Money.Value = player.leaderstats.Money.Value + earnings

end)
1 Like

Remove player, it should be game.ReplicatedStorage.GiveMoney:FireServer(earnings), the player is passed in automatically, if you pass it in, itā€™ll put it in the 2nd parameter

1 Like

You donā€™t need to send in the player when firing a remote event from the client, the player will always be the first parameter in :FireServer([Player], ā€¦)

Now I get this message because it does not know who is the player:

attempt to index nil with ā€˜leaderstatsā€™

If this si in yuor server script, remove it as well, probably overwriting unless you accidentally removed the player from OnServerEvent

No I am I am firing the server from a local script.

What is the script then? Because they are correct about removing player.

1 Like

I got u bro

make the code print ā€œearningsā€ and see wat this value actually is bcz its not a number

1 Like

What is your Server script as of now?

1 Like

It print for me the players name.

well thats your problem sir your adding a name to a number

Ok man make another parameter called ā€œearnings2ā€ and print it IT SHOULD BE the number u want

Did you remember to remove player from the FireServer or did you accidentally remove it from the OnServerEvent as well?

So what should I do with my script?

Please show us your Server script currently as I previously mentioned, the issue is either there or in your localscript

Itā€™s not an issue with numbers, itā€™s an issue with how the parameters and the arguments are set up

1 Like

change earnings to number so you can add em with a number

Here is my server script:
game.ReplicatedStorage.GiveMoney.OnServerEvent:Connect(function(player,earnings)

print(earnings)

player.leaderstats.Money.Value = player.leaderstats.Money.Value + earnings

end)

and here local:
game.ReplicatedStorage.GiveMoney:FireServer(earnings)

earnings is a parameter XD it becomes a number from the script that fired the remote so its parameter problem not ā€œearningsā€ problem as a string in parameter

1 Like

What should I do how do I turn it to a number

Make another parameter called ā€œearnings2ā€ and print it , It should be the number

1 Like