Hello!
So I simply want to know if you can use a Mouse1down function on an or line. Lemme give an example.
if Enum.Keycode.E or Mouse1Down then
Will that work? If not, what will?
Thanks!
Hello!
So I simply want to know if you can use a Mouse1down function on an or line. Lemme give an example.
if Enum.Keycode.E or Mouse1Down then
Will that work? If not, what will?
Thanks!
You can probably do this:
if Input.KeyCode == Enum.KeyCode.E or Input.UserInputType == Enum.UserInputType.MouseButton1 then
As long as you don’t check for any UserInputType prior, like keyboard input.
Great! Is there a way I can only make it work if you click a specific GUI? Like a TextButton or something?
inputservice.InputBegan:connect(function(i,g)
if i.UserInputType == Enum.UserInputType.Keyboard then
if i.KeyCode == Enum.KeyCode.E or i.UserInputType == Enum.UserInputType.MouseButton1 then
for _,Door in pairs(workspace.Items:GetChildren()) do
local Mag = (Door.Center.Position-game.Players.LocalPlayer.Character.HumanoidRootPart.Position).magnitude
if Mag <= Door.Range.Value then
Door.Event:FireServer()
break
end
end
end
end
end)
This is the code for it. Yo can see where I need you to come in xD
What I would do is handle key input separately from mouse input. You can use UserInputService for the key input, and then use the InputBegan/Ended or even activated events of the button for the mouse click.
The mouse input being a part of UserInputService just makes things a bit harder.
This should work
local PlayerGui = game.Players.LocalPlayer:WaitForChild("PlayerGui")
local UserInputService = game:GetService("UserInputService")
local Gui = PlayerGui.Test.Button -- Put your gui here
function KeyDownFunction()
-- Put your code here
end
local Entering = false
Gui.MouseEnter:Connect(function()
Entering = true
end)
Gui.MouseLeave:Connect(function()
Entering = false
end)
UserInputService.InputBegan:Connect(function(input)
if input == Enum.KeyCode.E and UserInputService:IsMouseButtonPressed(Enum.UserInputType.MouseButton1) and Entering then
KeyDownFunction()
end
end)
``