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)
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.
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)
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.
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…
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)
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)