Attempt to perform arithmetic (add) on string and number

Hey developers,
I was running my game for a new update, but then this error happened:

ServerScriptService.ScytheHandler:60: attempt to perform arithmetic (add) on string and number

I really need this fixed ASAP as my update needs to get out very soon.
Here’s a part of the script where there’s a problem script:

swipeEvent.OnServerEvent:Connect(function(plr,name)
	if plr.ScytheDebounce.Value == false then
		plr.ScytheDebounce.Value = true
		local amount = sytheData[name]["Strength"]
		local double = 1
		if plr.Data.DoubleStrength.Value == true then
			double = 2
		end
		plr.leaderstats.Strength.Value = plr.leaderstats.Strength.Value + (((amount + getMultiplier(plr,"Multiplier1"))*((plr.leaderstats.Rebirths.Value/10)))*double)
		waitM.Wait(0.38)
		plr.ScytheDebounce.Value = false
	end
end)

Is this function returning a number or a string?

(((amount + getMultiplier(plr,"Multiplier1")
1 Like

Sorry, I don’t script, I’m not the guy who made that.
In case you don’t know, though, Multiplier1 is the NumberValue

Well, the fix is very easy for this! You can’t add strings to numbers, but the handy converter tonumber() should fix that. It is a built in roblox function that turns strings to numbers. For the other way around, you could also do tostring().

Examples:

-- tonumber() example
local number_string = "10"
local number_int = 15

local thisWouldError = number_string + number_int -- This would error.
local CorrectMethod = tonumber(number_string) + number_int

Here is another example:

-- tostring example
local number_int = 15
local string_thing = "This number is: "

local this_Number_Is = string_thing..tostring(number_int)

Edit: Just saw you don’t script, let me kind of explain this easier. That error you were getting is saying that you cannot add numbers and strings together. Strings are things of text. These two do not mix, so you should use tonumber() to convert strings into numbers. This will prevent the error.

4 Likes

That looks great, I saw that before, but I do not know how to add that to the script. :thinking:

1 Like
swipeEvent.OnServerEvent:Connect(function(plr,name)
	if plr.ScytheDebounce.Value == false then
		plr.ScytheDebounce.Value = true
		local amount = sytheData[name]["Strength"]
		local double = 1
		if plr.Data.DoubleStrength.Value == true then
			double = 2
		end
		plr.leaderstats.Strength.Value = plr.leaderstats.Strength.Value .. tostring(((amount + getMultiplier(plr,"Multiplier1"))*((plr.leaderstats.Rebirths.Value/10)))*double)
		waitM.Wait(0.38)
		plr.ScytheDebounce.Value = false
	end
end)

If you are not the scripter, why didn’t you contact the scripter to fix the issue?

He’s currently offline, I contacted another scripter, Puhorka, but he didn’t seem to figure it out.

Quick question, is the value in the player (plr.leaderstats.Strength.Value) a string or a number value? If you don’t know, check the script where it creates these values.

The error is still there, the same as ever.

Is strength a string or number value? It depends, because if it is a number value you need tonumber(). I could add the function for you since you don’t know how…

The strength leaderstat is an IntValue

Can you tell me which line exactly is line 60?

Right, so you need to use tonumber(). This is pretty much all the info I need. Could you tell me what line of code is 60? Just copy and paste it or something

This line you made:
plr.leaderstats.Strength.Value = plr.leaderstats.Strength.Value … tostring(((amount + getMultiplier(plr,“Multiplier1”))*((plr.leaderstats.Rebirths.Value/10)))*double)

plr.leaderstats.Strength.Value = plr.leaderstats.Strength.Value … tostring(((amount + getMultiplier(plr,“Multiplier1”))*((plr.leaderstats.Rebirths.Value/10)))*double)

Is plr.leaderstats.Strength a NumberValue/IntValue or a StringValue?

IntValue :thinking: :thinking:

I think this might be your answer.

swipeEvent.OnServerEvent:Connect(function(plr,name)
	if plr.ScytheDebounce.Value == false then
		plr.ScytheDebounce.Value = true
		local amount = sytheData[name]["Strength"]
		local double = 1
		if plr.Data.DoubleStrength.Value == true then
			double = 2
		end
		plr.leaderstats.Strength.Value = plr.leaderstats.Strength.Value + tonumber((((amount + getMultiplier(plr,"Multiplier1"))*((plr.leaderstats.Rebirths.Value/10)))*double))
		waitM.Wait(0.38)
		plr.ScytheDebounce.Value = false
	end
end)
1 Like

I’ll try that, and see if it works.