So I have a UserInputService function which detects if the input is MouseButton1 but the “GameProssesedEvent” is always true, I think the mouse might be triggering anything else, but my game is small and all the code is from myself so I would know.
I am really new to using “GameProssesedEvent” so I could be doing something wrong, here is the whole script:
local UserInputService = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Abilities = ReplicatedStorage:WaitForChild("Events"):WaitForChild("Abilities")
local Player = game.Players.LocalPlayer
local character = Player.Character or Player.CharacterAdded:Wait()
local Root = character:WaitForChild("HumanoidRootPart")
local Animation = character:WaitForChild("Humanoid"):LoadAnimation(script:WaitForChild("Animation"))
local Animation2 = character:WaitForChild("Humanoid"):LoadAnimation(script:WaitForChild("Animation2"))
--Settings
local Damage = 5
local Debounce = Animation.Stopped
local Debounce2 = Animation2.Stopped
local Keybind = Enum.UserInputType.MouseButton1
local CanPunch = true
UserInputService.InputBegan:Connect(function(input, GameProssesedEvent)
--The "Keybind variable used to replace this ⏬
if input.UserInputType == Enum.UserInputType.MouseButton1 and not GameProssesedEvent then
if CanPunch == true then
CanPunch = false
local AnimChosen = math.random(1, 2)
if AnimChosen == 1 then
Animation:Play()
Animation.Looped = false
wait(0.2)
Abilities.Punch:FireServer(Damage)
Debounce:Wait()
CanPunch = true
elseif AnimChosen == 2 then
Animation2:Play()
Animation.Looped = false
wait(0.2)
Abilities.Punch:FireServer(Damage)
Debounce2:Wait()
CanPunch = true
end
end
end
end)
The script is supposed to play and animation and fire a remote event (which works when I remove the “GameProsesedEvent” detection). –EDIT: I just tried MouseButton2 and that worked… Why would mouseButton1 be the problem???
I really need help with this because it messes with a core game mechanic. Any feedback helps!
i mean, you could just remove the and not GameProssesedEvent from your code, but that would make it so it fires every time you click.
I would probably recommend changing your code to:
local UserInputService = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Abilities = ReplicatedStorage:WaitForChild("Events"):WaitForChild("Abilities")
local Player = game.Players.LocalPlayer
local character = Player.Character or Player.CharacterAdded:Wait()
local Root = character:WaitForChild("HumanoidRootPart")
local Animation = character:WaitForChild("Humanoid"):LoadAnimation(script:WaitForChild("Animation"))
local Animation2 = character:WaitForChild("Humanoid"):LoadAnimation(script:WaitForChild("Animation2"))
--Settings
local Damage = 5
local Debounce = Animation.Stopped
local Debounce2 = Animation2.Stopped
local Keybind = Enum.UserInputType.MouseButton1
local CanPunch = true
mouse.Button1Down:Connect(function()
if CanPunch == true then
CanPunch = false
local AnimChosen = math.random(1, 2)
if AnimChosen == 1 then
Animation:Play()
Animation.Looped = false
wait(0.2)
Abilities.Punch:FireServer(Damage)
Debounce:Wait()
CanPunch = true
elseif AnimChosen == 2 then
Animation2:Play()
Animation.Looped = false
wait(0.2)
Abilities.Punch:FireServer(Damage)
Debounce2:Wait()
CanPunch = true
end
end
end)
Here’s the script I have now but its not detecting my mouse.
local UserInputService = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Abilities = ReplicatedStorage:WaitForChild("Events"):WaitForChild("Abilities")
local Player = game.Players.LocalPlayer
local character = Player.Character or Player.CharacterAdded:Wait()
local Root = character:WaitForChild("HumanoidRootPart")
local mouse = Player:GetMouse()
local Animation = character:WaitForChild("Humanoid"):LoadAnimation(script:WaitForChild("Animation"))
local Animation2 = character:WaitForChild("Humanoid"):LoadAnimation(script:WaitForChild("Animation2"))
--Settings
local Damage = 5
local Debounce = Animation.Stopped
local Debounce2 = Animation2.Stopped
local Keybind = Enum.UserInputType.MouseButton1
local CanPunch = true
mouse.Button1Down:Connect(function()
print("clicked")
if CanPunch == true then
CanPunch = false
local AnimChosen = math.random(1, 2)
if AnimChosen == 1 then
Animation:Play()
Animation.Looped = false
wait(0.2)
Abilities.Punch:FireServer(Damage)
Debounce:Wait()
CanPunch = true
elseif AnimChosen == 2 then
Animation2:Play()
Animation.Looped = false
wait(0.2)
Abilities.Punch:FireServer(Damage)
Debounce2:Wait()
CanPunch = true
end
end
end)
Did you print when you were checking if the UserInput was MouseButton1? It could be that it’s not meeting that condition for some reason. The code should work, since I’m testing how yours is structured.
It can also be that there’s hidden UI elements within the players PlayerGui that triggers the ProcessedEvent.