Mouse.Hit.Position not working

I’m trying to make a V2 of my gun system, however I found this issue. Instead of passing over the mouse hit position to the server it passes the player instance, I am so confused.

Server Script (GunHandler):

game.ReplicatedStorage.GunRemotes.ShootGun.OnServerEvent:Connect(function(mousePos, startpoint, tool, dmg, headdmg, range)
	local origin = startpoint
	local direction = (startpoint - mousePos).unit * range
	local raycastParams = RaycastParams.new()
	raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
	raycastParams.FilterDescendantsInstances = IgnoreList
	raycastParams.IgnoreWater = true
	local results = workspace:Raycast(origin, direction, raycastParams)
	if results then
		print(results)
	end
end)

Local script:

mouse.Button1Down:Connect(function()
	if available then
		if Semi ~= true then
			isHeld = true
			repeat
				for index = 1, Firerate do
					local startPos = muzzle.Position
					local tool = script.Parent
					print(mouse.Hit.Position)
					gunRemote.ShootGun:FireServer(game.Players.LocalPlayer:GetMouse().Hit.p, startPos, tool, Damage, headDamage, range)
				end
				wait(RPM/60)
			until isHeld == false or not available
		else

		end
	end
end)

The only error is: “ServerScriptService.GunHandler:15: invalid argument #2 (Vector3 expected, got Instance)”

1 Like

First parameter of OnServerEvent is always the player who fired the event, your code works fine except for this, change it to

game.ReplicatedStorage.GunRemotes.ShootGun.OnServerEvent:Connect(function(player,mousePos, startpoint, tool, dmg, headdmg, range)

That way it will account for the palyer instance of who fired the event, as it thinks mousePos is the parameter to put the player who fired the event

I just realized the first parameter of a RemoteEvent is a player instance, I keep forgetting this I’m so sorry, thank you for the help! I appreciate it so much thanks for reminding!

1 Like

Anytime! Glad I could remind you about that! If you have anymore issues don’t be afraid to make another post!