Keypress to Mouse click change

My script uses Q for activation on a tool. I want to change it to Mouseclick.

if KeyCode == Enum.KeyCode.Q then
		SelectSpell(SpellGui:WaitForChild("SpellGuiFrame"):WaitForChild("Flame"),SpellGui)
	end
end)

I tried changing i to this but it wont recognize mouse click.

if KeyCode == Enum.KeyCode.MouseButton1Click then
		SelectSpell(SpellGui:WaitForChild("SpellGuiFrame"):WaitForChild("Flame"),SpellGui)
	end
end)

Im guess keycode wont work with mouseclick. I have tied a few others ways as tool.activation. but cant figure out the correct format.

Change KeyCode to UserInputType. So:

KeyCode == Enum.KeyCode.MouseButton1Click

Would be:

UserInputType == Enum.UserInputType.MouseButton1

and the input type doesn’t require “Click” at the end.

Some more info:

1 Like

You can also do:

local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()

Mouse. Button1Down:Connect(function()
   -- Your code here
end)

i tried this and it did not work.

	if UserInputType == Enum.UserInputType.MouseButton1 then
		SelectSpell(SpellGui:WaitForChild("SpellGuiFrame"):WaitForChild("Flame"),SpellGui)
	end
end)

i think mouseclick is selecting the spell now but not using it also. I need it to select the spell and activate the tool at the same time.

I need to see a larger part of the script since you’ll need to declare UserInputType for it to be used in this conditional statement.