ServerScriptService.ThrowServer:13: attempt to perform arithmetic (mul) on nil and number?

what i want to achieve is Mutiply my variable with my other variable but it gives this error ServerScriptService.ThrowServer:13: attempt to perform arithmetic (mul) on nil and number

this is my server sided code

local ts = game:GetService("TweenService")
game.ReplicatedStorage.OnThrow.OnServerEvent:Connect(function(Player,Velocity,Target,Pos)


	local Ball = script.Snowball:Clone()
	if Player.Team == game.Teams["Red Ranger"] then
		Ball.Color = Color3.fromRGB(255, 162, 165)
	elseif Player.Team == game.Teams["Blue Blobs"] then
		Ball.Color = Color3.fromRGB(163, 162, 255)
	end
	Ball.Parent = game.Workspace
	Ball.Position = Player.Character.Head.Position
	Ball.Velocity = Pos * Velocity -- error usually occurs here when i am not pointing at a humanoid
	
	
	if Target and Target.Parent:FindFirstChild("Humanoid") then
		--	if game.Players:GetPlayerFromCharacter(Target).Team == Player.Team then
		-- 	Damage = 0
		--	end
		local Distance = math.round((Player.Character.Head.Position-Target.Parent.Head.Position).Magnitude)
		if Distance < Velocity/7.5 then
			local Dmg = Velocity/20+(66.666-(Distance/2))/2
			Target.Parent.Humanoid:TakeDamage(Dmg)
		end
		if Target.Parent.Humanoid.Health == 0 then
			print("death")
		end
	end
	
end)

This is client sided

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local rs = game:GetService("RunService")
local event = game.ReplicatedStorage.OnThrow
local db = false
local Speed = 100
local Hold = false
local MaxSpeed = 1000

mouse.Button1Down:Connect(function()
	if not db then
		Hold = true
		script.Parent.Visible = true
	end
end)
mouse.Button1Up:Connect(function()
	
	Hold = false
	script.Parent.Visible = false
	
	if not db and not Hold then
		db = true
		local Target = mouse.Target
		if Target and Target.Parent:FindFirstChild("Humanoid") then
			event:FireServer(Speed,Target,mouse.Hit.LookVector)
			script.Whoosh.Volume = Speed/200
			script.Whoosh:Play()
		else
			event:FireServer(Speed)
			script.Whoosh.Volume = Speed/200
			script.Whoosh:Play()
		end	
		
		wait(0.5)
		Speed = 100
		db = false
	end
	
end)

rs.RenderStepped:Connect(function()
	script.Parent.Front:TweenSize(UDim2.fromScale(1,1-(Speed/MaxSpeed)+0.1),"Out","Sine",0.25)
end)

while true do
	if Hold == true and Speed < MaxSpeed then
		Speed = Speed + 100
	end
	wait(0.25)
end

as you can see i mentioned a comment in the server sided script please read it

1 Like

This is because whenever you’re not aiming at a humanoid, you’re most likely aiming at something with no position, such as the sky, causing it to throw an error. You’re better off using mouse.Hit.p in the local script.

but why dosent lookvector work? it is a cframe and wont position not work?

The issue comes from your conditional that splits the logic based on whether or not the player click on a humanoid. If they didn’t, the code doesn’t provide enough information to the server because it only passes on speed.

In this block on your client script…

local Target = mouse.Target
if Target and Target.Parent:FindFirstChild("Humanoid") then
	event:FireServer(Speed,Target,mouse.Hit.LookVector)
	script.Whoosh.Volume = Speed/200
	script.Whoosh:Play()
else
	event:FireServer(Speed)
	script.Whoosh.Volume = Speed/200
	script.Whoosh:Play()
end

…changing event:FireServer(Speed) in your else statement to event:FireServer(Speed,nil,mouse.Hit.LookVector) will allow the server script to execute the command.

ow oh yea i didnt saw that thing over there lol silly mistakes thanks

1 Like