I’m trying to make a ability where if you hold down the mouse you can wait to release the ability, but for some reason the remote event fires a couple of times even though I only click once.
local Tool = script.Parent
wait()
local Anim = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.Parent.Animation)
local Hold = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.Hold)
local Idle = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.Idle)
local mouse = game.Players.LocalPlayer:GetMouse()
local UIS = game:GetService("UserInputService")
local cd = false
Tool.Activated:Connect(function()
if cd == true then return end
cd = true
coroutine.wrap(function()
wait(5)
cd = false
end)()
script.Add:FireServer("add")
Hold:Play()
Hold:GetMarkerReachedSignal("Hold"):Connect(function(paramString)
Idle:Play()
if not UIS:IsMouseButtonPressed(Enum.UserInputType.MouseButton1) then
Idle:Stop()
print("FIRED")
script.RemoteEvent:FireServer(mouse.Hit.p)
else
repeat wait() until not UIS:IsMouseButtonPressed(Enum.UserInputType.MouseButton1)
Idle:Stop()
print("FIRED")
script.RemoteEvent:FireServer(mouse.Hit.p)
end
end)
end)
Watch Desktop 2024.03.22 - 22.01.09.10 | Streamable video of the issue