Key check not working for some reason

Im working on a gun system but for some reason when I use UIS to check on key down, it will print out that its mousebutton1 but when I check it, nothing happens


UserInputService.InputBegan:Connect(function(Key, GPE)
		if GPE then return end
		
		print("Input detected:", Key.UserInputType)
		
		if Key == Enum.UserInputType.MouseButton1 and LocalPlayer:GetAttribute("Aimming") then
			print("KEY DOWN")
			local Head = Character and Character:FindFirstChild("Head")
			if not Head then
				return
			end

			local Origin = WeaponEquiped.barrel.Position
			local Direction = (Mouse.Hit.Position - Origin).Unit

			local Time = workspace:GetServerTimeNow()
			
			SecureCast.Cast(LocalPlayer, "Bullet", Origin, Direction, Time)
			WeaponServer.GunFire:Fire(Origin, Direction, Time)
			
		end
	
	end)

No idea why this is happening

(I removed aimming check, was not a issue, then I added a else statement and it was saying that the key was NOT mousebutton1 somehow? Even though it prints it out as being so.

You need to do

if Key.UserInputType == Enum.UserInputType.MouseButton1 and ..... then

Key here is an InputObject, you can’t just compare it like that

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.