Attempt to perform arithmetic (mul) on table and number

I am getting an error when I try to use workspace:Raycast(), the error is here:

attempt to perform arithmetic (mul) on table and number

Local Script:

local mouse = game.Players.LocalPlayer:GetMouse()

script.Parent.Activated:Connect(function()
	script.Parent.Fire:FireServer(mouse.Hit.Position)
end)

Server Script:

script.Parent.Fire.OnServerEvent:Connect(function(player,mousePos)

	local raycastParams = RaycastParams.new()
	raycastParams.FilterDescendantsInstances = {player.Character}
	raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
	
	local raycastResult = workspace:Raycast(script.Parent.Handle.Position,{mousePos - script.Parent.Handle.Position}*300,raycastParams)
	
	if raycastResult then
		local hitPart = raycastResult.Instance
		local model = hitPart:FindFirstAncestorOfClass("Model")
		
		if model then
			if model:FindFirstChild("Humanoid") then
				model.Humanoid.Health -= 30
			end
		end
	end
	
end)

The error is on line 7 in the Server Script, I am new to raycasting and used a tutorial to help me, any help is appreciated.

It should be:

(mousePos - script.Parent.Handle.Position).Unit * 300

The error happens because you are using {} which is a table constructor. And as the error says, you are trying to multiple a number and a table.

2 Likes

Thank you, that was a very quick response, it works properly now.