Attempt to perform arithmetic (sub) on number and nil

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? : Fix this error.

  2. What is the issue? It’s giving the error:

Workspace.Rocket Laucher Teste.Seat.Script:18: attempt to perform arithmetic (sub) on number and nil

  1. What solutions have you tried so far? I tried to instantiate the position given by the client

Script Server

local function lerp(p0,p1,t)
	return p0*(1-t) + p1*t --Error Line
end

fire.OnServerEvent:Connect(function(p,pos)
	
	for i = 1, speed do
		local t = i/speed
		local a1 = projectiles.a1
		local a2 = projectiles.a2
		local a3 = projectiles.a3
		local a4 = projectiles.a4
		local a5 = projectiles.a5
		local a6 = projectiles.a6
		local a7 = projectiles.a7
		local a8 = projectiles.a8
		local a9 = projectiles.a9
		local a10 = projectiles.a10
		local a11 = projectiles.a11
		
		local l1 = lerp(a1.Position,p1s.a1.Position,t)
		local l2 = lerp(p1s.a1.Position,pos)
		local quad = lerp(l1,l2,t)
		
		a1.CFrame = CFrame.new(quad)
		
		l1 = lerp(a2.Position,p1s.a2.Position,t)
		l2 = lerp(p1s.a2.Position,pos)
		quad = lerp(l1,l2,t)
		a2.CFrame = CFrame.new(quad)
		
		l1 = lerp(a3.Position,p1s.a3.Position,t)
		l2 = lerp(p1s.a3.Position,pos)
		quad = lerp(l1,l2,t)
		a3.CFrame = CFrame.new(quad)
		
		l1 = lerp(a4.Position,p1s.a4.Position,t)
		l2 = lerp(p1s.a4.Position,pos)
		quad = lerp(l1,l2,t)
		a4.CFrame = CFrame.new(quad)
		
		l1 = lerp(a5.Position,p1s.a5.Position,t)
		l2 = lerp(p1s.a5.Position,pos)
		quad = lerp(l1,l2,t)
		a5.CFrame = CFrame.new(quad)
		
		l1 = lerp(a6.Position,p1s.a6.Position,t)
		l2 = lerp(p1s.a6.Position,pos)
		quad = lerp(l1,l2,t)
		a6.CFrame = CFrame.new(quad)
		
		l1 = lerp(a7.Position,p1s.a7.Position,t)
		l2 = lerp(p1s.a7.Position,pos)
		quad = lerp(l1,l2,t)
		a7.CFrame = CFrame.new(quad)
		
		l1 = lerp(a8.Position,p1s.a8.Position,t)
		l2 = lerp(p1s.a8.Position,pos)
		quad = lerp(l1,l2,t)
		a8.CFrame = CFrame.new(quad)
		
		l1 = lerp(a9.Position,p1s.a9.Position,t)
		l2 = lerp(p1s.a9.Position,pos)
		quad = lerp(l1,l2,t)
		a9.CFrame = CFrame.new(quad)
		
		l1 = lerp(a10.Position,p1s.a10.Position,t)
		l2 = lerp(p1s.a10.Position,pos)
		quad = lerp(l1,l2,t)
		a10.CFrame = CFrame.new(quad)
		
		l1 = lerp(a11.Position,p1s.a11.Position,t)
		l2 = lerp(p1s.a11.Position,pos)
		quad = lerp(l1,l2,t)
		a11.CFrame = CFrame.new(quad)
		
		task.wait()
	end
	
end)

Script Client

mouse.Button1Up:Connect(function()
	if canShoot == true then
		canShoot = false
		local hit = mouse.Hit
		local hitPos = hit.Position
		fire:FireServer(hitPos)
		task.wait(2)
		canShoot = true
	end
end)

It’s my first topic, I don’t know if it will be good

One of your arguments being sent to lerp doesn’t exist. Try printing each argument to debug which one doesn’t exist.

Actually, here’s your issue:

l2 = lerp(p1s.a2.Position,pos)

You’re calling lerp with 2 arguments, but 3 is needed or else it’ll throw an error.

Yes, i forget t arg.
Thank You!

1 Like