Attempt to perform arithmetic (unm) on nil

local script

local player = game.Players.LocalPlayer
local debounce = false
local character = player.Character
local root = character.HumanoidRootPart
local mouse = player:GetMouse()
local UIS = game:GetService("UserInputService")
local fireevent = game.ReplicatedStorage.AbilityEvents.Push
local spell = false


player.Chatted:Connect(function(msg)
	if string.find(msg:lower(),"movere") ~= nil and debounce == false and spell == false then
		spell = true
	end
end)

mouse.Button1Down:Connect(function()
	local mousetarg = mouse.Target
	if mouse.Target:IsA("BasePart") then
		if mouse.Target.Parent:FindFirstChild("Humanoid") and debounce == false and spell == true then
			debounce = true
			if (mousetarg.Position - root.Position).magnitude <15 and debounce == true then
				fireevent:FireServer("TelePush", mousetarg)
				wait(10)
				spell = false
				debounce = false
				print("cooldown over!!")
			end
		end
	end
end)

server script

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local Event = ReplicatedStorage.AbilityEvents:WaitForChild("Push")
local Debris = game:GetService("Debris")
local Mouse = ReplicatedStorage:WaitForChild("Mouse")
local anim = script.Animation
local Lifting = {}

local function getDamage(Player)
	local Rank = Player:WaitForChild("GroupRank").Value
	if Rank == 1 then -- Novice
		return 10
	elseif Rank == 2 then -- Intermediate
		return 14
	elseif Rank == 3 then -- Growing
		return 17
	elseif Rank == 4 then -- Talented
		return 20
	elseif Rank == 5 then -- Experienced
		return 26
	elseif Rank == 6 then -- Gifted
		return 27
	elseif Rank == 7 then -- Powerful
		return 32
	elseif Rank == 8 then -- Apprentice
		return 35
	elseif Rank == 9 then -- Mastery
		return 40
	elseif Rank == 15 then -- Intern
		return 75
	--[[elseif Rank == 20 then -- Intern
		return 60
	elseif Rank == 22 then -- Professor
		return 60
	elseif Rank == 24 then -- Senior Lecturer
		return 60
	elseif Rank == 26 then -- Academician
		return 65
	elseif Rank == 28 then -- Head Consutlant
		return 250
	elseif Rank == 30 then -- Witch Council
		return 250
	elseif Rank == 32 then -- Head Councillor
		return 70]]
	elseif Rank == 40 then -- Professor
		return 70
	elseif Rank == 44 then -- Senior Professor
		return 75
	elseif Rank == 50 then -- Supremacy
		return 50
	elseif Rank == 251 then -- Auspex
		return 90
	elseif Rank == 252 then -- Governor
		return 140
	elseif Rank >= 253 and Rank <= 254 then -- Council & Headmaster
		return 9999999999999999999999
	elseif Rank == 255 then -- Ethereal Overseer
		return 9999999999999999999999
	end
end

local function getPush(Player)
	local Rank = Player:WaitForChild("GroupRank").Value
	if Rank == 1 then -- Novice
		return 10
	elseif Rank == 2 then -- Intermediate
		return 12
	elseif Rank == 3 then -- Growing
		return 18
	elseif Rank == 4 then -- Talented
		return 25
	elseif Rank == 5 then -- Experienced
		return 20
	elseif Rank == 6 then -- Gifted
		return 25
	elseif Rank == 7 then -- Powerful
		return 30
	elseif Rank == 8 then -- Apprentice
		return 35
	elseif Rank == 9 then -- Mastery
		return 40
	elseif Rank == 15 then -- Intern
		return 45
	--[[elseif Rank == 20 then -- Intern
		return 60
	elseif Rank == 22 then -- Professor
		return 60
	elseif Rank == 24 then -- Senior Lecturer
		return 60
	elseif Rank == 26 then -- Academician
		return 65
	elseif Rank == 28 then -- Head Consutlant
		return 250
	elseif Rank == 30 then -- Witch Council
		return 250
	elseif Rank == 32 then -- Head Councillor
		return 70]]
	elseif Rank == 40 then -- Professor
		return 65
	elseif Rank == 44 then -- Senior Professor
		return 75
	elseif Rank == 50 then -- Supremacy
		return 500
	elseif Rank == 251 then -- Auspex
		return 800
	elseif Rank == 252 then -- Governor
		return 900
	elseif Rank >= 253 and Rank <= 254 then -- Council & Headmaster
		return 9999999999999999999999
	elseif Rank == 255 then -- Ethereal Overseer
		return 9999999999999999999999
	end
end

Event.OnServerEvent:Connect(function(Player, Type, Mouse)
	local success, errorMessage = pcall(function()
		if Type == "TelePush" then
			local loadedanim = Player.Character.Humanoid:LoadAnimation(anim)
			loadedanim:Play()
			local Damage = getDamage(Player)
			local Distance = getPush(Player)
			local targetCharacter = Mouse.Parent
			local targetHumanoid = targetCharacter:FindFirstChild("Humanoid")
			if targetHumanoid then
				targetHumanoid.ragdoll.Value = true
				local bodyPos = Instance.new("BodyPosition")
				local targetPos = targetCharacter.UpperTorso.Position
				local plrPos = Player.Character.UpperTorso.Position
				bodyPos.Position = CFrame.new(plrPos, Vector3.new(targetPos.X, targetPos.Y, targetPos.Z)) * CFrame.new(0, 0, -Distance).Position + Vector3.new(0, 5, 0)
				bodyPos.Parent = targetCharacter.UpperTorso
				Debris:AddItem(bodyPos, 0.5)
				local Sound = script.Woosh:Clone()
				Sound.Parent = targetCharacter.UpperTorso
				Sound.Stopped:Connect(function()
					Sound:Destroy()
				end)
				Sound:Play()
				targetHumanoid:TakeDamage(Damage)
				wait(4)
				if targetHumanoid then
					if targetHumanoid.Health > 0 and not targetCharacter:FindFirstChild("Dead") then
						targetHumanoid.ragdoll.Value = false
						loadedanim:Stop()
					end
				end
			end
		end
	end)
	if errorMessage then
		warn(errorMessage)
	end
end)

Tough to decipher when you just give an error and two very long scripts. For starters you shouldn’t wrap so much code in a pcall, especially if it is the entire function’s contents. That would help give a line number so we know exactly where the problem occurs.

Since it’s a multiply by nil would recommend separating these values out and printing each of them until you find nil

print("player", plrPos)
print("target", targetPos)
print("Distance", Distance)
local CFrameA = CFrame.new(plrPos, targetPos)
print("A", CFrameA)
local CFrameB = CFrame.new(0, 0, -Distance)
print("B", CFrameB)
bodyPos.Position = A * B.p + Vector3.new(0, 5, 0)
1 Like

The error was not a (mul), it was (unm).

does this make any difference to how i would fix it?

I have no idea, it would help to start by removing the pcall and showing the line number where the error occurs.

1 Like

Unm is negative.

var = nil
print(-var)
1 Like

I removed the pcall and the error is on line 129, which is

	bodyPos.Position = CFrame.new(plrPos, Vector3.new(targetPos.X, targetPos.Y, targetPos.Z)) * CFrame.new(0, 0, -Distance).Position + Vector3.new(0, 5, 0)

Distance is probably nil. I would start with that.

then your Distance is nil the getPush function returns nil if the player’s rank is a variety of values, you should add a default push value by putting a else return 1 at the end of it

OH i know the issue, I was using test mode so it just gave me 2 clones of my avatar, they didn’t have a rank in the group since they’re just clones.

yep, adding a value to their group rank fixed it!

Unrelated but avoid employing coding practices like this.

Event.OnServerEvent:Connect(function(Player, Type, Mouse)
	local success, errorMessage = pcall(function()
		if Type == "TelePush" then
			local loadedanim = Player.Character.Humanoid:LoadAnimation(anim)
			loadedanim:Play()
			local Damage = getDamage(Player)
			local Distance = getPush(Player)
			local targetCharacter = Mouse.Parent
			local targetHumanoid = targetCharacter:FindFirstChild("Humanoid")
			if targetHumanoid then
				targetHumanoid.ragdoll.Value = true
				local bodyPos = Instance.new("BodyPosition")
				local targetPos = targetCharacter.UpperTorso.Position
				local plrPos = Player.Character.UpperTorso.Position
				bodyPos.Position = CFrame.new(plrPos, Vector3.new(targetPos.X, targetPos.Y, targetPos.Z)) * CFrame.new(0, 0, -Distance).Position + Vector3.new(0, 5, 0)
				bodyPos.Parent = targetCharacter.UpperTorso
				Debris:AddItem(bodyPos, 0.5)
				local Sound = script.Woosh:Clone()
				Sound.Parent = targetCharacter.UpperTorso
				Sound.Stopped:Connect(function()
					Sound:Destroy()
				end)
				Sound:Play()
				targetHumanoid:TakeDamage(Damage)
				wait(4)
				if targetHumanoid then
					if targetHumanoid.Health > 0 and not targetCharacter:FindFirstChild("Dead") then
						targetHumanoid.ragdoll.Value = false
						loadedanim:Stop()
					end
				end
			end
		end
	end)
	if errorMessage then
		warn(errorMessage)
	end
end)