ServerScriptService.PistolFire:8: attempt to perform arithmetic (sub) on nil and Vector3

I want to make a simple gun system and it gave me this error

18:16:40.159 ServerScriptService.PistolFire:8: attempt to perform arithmetic (sub) on nil and Vector3 - Server - PistolFire:8

I’ve tried making the raycastparams different but I don’t know many options

game.ReplicatedStorage.PistolEvent.OnServerEvent:Connect(function(Player, PlayerMouse, FireTool)
	FireTool:WaitForChild("Handle").Fire:Play()
	
	local raycastParams = RaycastParams.new()
	raycastParams.FilterDescendantsInstances = {Player.Character}
	raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
	
	local raycastResult = workspace:Raycast(FireTool:WaitForChild("Handle").Position, (PlayerMouse - FireTool:WaitForChild("Handle").Position)*300,raycastParams)
	
	if raycastResult then
		local Model = PlayerMouse:FindFirstAncestorOfClass("Model")
		if Model:WaitForChild("Humanoid") then
			Model.Humanoid.Health -= 25
			FireTool:WaitForChild("Handle").HitMarker:Play()
			PlayerMouse.Icon = "rbxassetid://7193947094"
			wait()
			PlayerMouse.Icon = "rbxassetid://62814275"
		end
	end
end)```
1 Like

What is PlayerMouse? If it’s the mouse object, the mouse object doesn’t exist on the server, you would need to pass Mouse.Hit.Position

1 Like

Ahh, thank you for the support, let me try this.

Firstly, I think you cant really get a playermouse and send to server. Because it have this following note on a player:GetMouse()
image
I think you need to try sending only a data from a mouse (ex. position of a mouse or mouse target) to a server

1 Like

Thank you so much, this worked I really appreciate it, and I made some improvements as well.