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

Attempt to perform arithmetic (sub) on number and nil error?

I keep getting the error "Attempt to perform arithmetic (sub) on number and nil", I'm not sure what it means and haven't been able to find anything out about it.

Serverscript:

local ModuleScale = require(game:GetService("ServerScriptService").Scaling)
player.Character.Conditions.Health.Value -= ModuleScale.Scaler(Scaling, Damage)

Modulescript:

local Scale = {}
local Players = game:GetService("Players")
local Player = Players:GetPlayers()[1] or Players.PlayerAdded:Wait()
local Char = Player.Character


function Scale.Scaler(Scaling, Damage)
	if Scaling == "D" then
		local Factor = 45 / Char.ComboStats.Damage.Value
		local Dmg = Damage * Factor
		return math.round(Dmg)
	end
end

return Scale

1 answer

✓ Accepted answer

your module script failed to return a number therefor the Attempt to perform arithmetic (sub) on number and nil

--[[
number = player.Character.Conditions.Health.Value
nil = ModuleScale.Scaler()
Sub = Subtract
]]

2 comments

0

How would the module fail to return a number?

0

its prob this "if Scaling == "D" then" if scaling is not D it returns nothing therefor nil

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