Why does this happen when I try to add XBOX support?

So this gun works perfectly fine on keyboard and tablet but not when I try to implement XBOX support?

Does anyone know what I can do?

The problem is it shoots to the left of where I aimed.

https://i.gyazo.com/c5d58af9062fb6e3af699a3d7299494b.mp4

Client Script:

UserInputService.InputBegan:Connect(function(InputObject, GameHandledEvent)
	if GameHandledEvent or not ExpectingInput then return end
	if InputObject.UserInputType == Enum.UserInputType.MouseButton1 or InputObject.UserInputType == Enum.UserInputType.Gamepad1 then
		MouseEvent:FireServer(GetMouseDirection(InputObject.Position))
	end
end)

Try Input.KeyCode == Enum.KeyCode.RightTrigger

(Not sure if is the exact enum name)

The problem wasn’t that it won’t shoot it’s the problem that it shoots to the left and not where it’s suppose to.

are you using FastCast? If so, try using the mouse.hit unit vector (hit - origin).unit, im not sure if xbox is using mouse or not, you’d have to see

we’re already using that, XBOX is the only problem.

did you try replacing GetMouseDirection(InputObject.Position) with (mouse.Hit.p - handle.Position).unit

if you haven’t already, put a reference for mouse and handle which mouse is the player mouse, and handle is the gun’s handle (what you are holding)

1 Like

aaaaaaaaaaaa thanks! It worked when I removed the GetMouseDirection function and added the mouse pos - the hand pos!

Thanks so much!

UserInputService.InputBegan:Connect(function(InputObject, GameHandledEvent)
	if GameHandledEvent or not ExpectingInput then return end
	if InputObject.UserInputType == Enum.UserInputType.MouseButton1 or InputObject.KeyCode == Enum.KeyCode.ButtonR2 then
		local FireDirection = (Mouse.Hit.Position - Handle.Position).Unit
		MouseEvent:FireServer(FireDirection)
	end
end)
3 Likes