Tool (Server Script)
local Cooldown = false
local onGoing = false
local debris = game:GetService("Debris")
local UIS = game:GetService("UserInputService")
local tool = script.Parent
local name = tool.Name
local CD = 0.1
local handle = tool.Handle
local idle = tool.Idle
local dash = tool.Dash
local event1 = tool.DashEvent
local event2 = tool.MeleeEvent
local event3 = tool.CancelMelee
local idleAnim
local dashAnim
local GlobalCooldown
local slashanimation
local slash = tool.Slash1
local slash2 = tool.Slash2
event2.OnServerEvent:Connect(function()
local player = script.Parent.Parent
local humanoid = player:FindFirstChild("Humanoid")
if Cooldown == false and player:FindFirstChild("GLOBALCOOLDOWN") == nil then
onGoing = true
Cooldown = true
if not onGoing then return end
local boolValue = Instance.new("BoolValue", player)
boolValue.Name = "GLOBALCOOLDOWN"
GlobalCooldown = boolValue
local animate = player:FindFirstChild("Animate")
animate.Enabled = false
local Animator = humanoid:WaitForChild("Animator")
local animationTrack = Animator:LoadAnimation(slash)
animationTrack:Play()
slashanimation = animationTrack
animationTrack.Stopped:Wait()
animationTrack = Animator:LoadAnimation(slash2)
animationTrack:Play()
slashanimation = animationTrack
animationTrack.Stopped:Wait()
animationTrack:Destroy()
animate.Enabled = true
boolValue:Destroy()
Cooldown = false
onGoing = false
end
end)
event3.OnServerEvent:Connect(function()
local player = script.Parent.Parent
if onGoing == true and Cooldown == true then
Cooldown = false
onGoing = false
player:FindFirstChild("Animate").Enabled = true
if GlobalCooldown ~= nil and GlobalCooldown:IsA("BoolValue") then
GlobalCooldown:Destroy()
end
end
end)
Tool (Local Script)
local UIS = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local playerMouse = player:GetMouse()
local remoteEvent = script.Parent:WaitForChild("DashEvent")
local remoteEvent2 = script.Parent:WaitForChild("MeleeEvent")
local remoteEvent3 = script.Parent:WaitForChild("CancelMelee")
local tool = script.Parent
local ongoing = false
--This part of the code for InputBegan works and does not need to be addressed.
UIS.InputBegan:Connect(function(keyProcessed,gameProcessed)
if keyProcessed.KeyCode == Enum.KeyCode.E and player.Character:FindFirstChildOfClass("Tool") then
remoteEvent:FireServer(player, keyProcessed.KeyCode)
end
end)
playerMouse.Button1Down:Connect(function()
if ongoing == false and tool.Parent == player.Character then
ongoing = true
remoteEvent2:FireServer()
task.wait(0.03)
playerMouse.Button1Up:Wait()
ongoing = false
remoteEvent3:FireServer()
end
end)
For context, I’m trying to make a melee weapon in a tool with multiple keybinds and a standard mouseclick attack. The one I’m going to be specifically focusing on which is the problem of my post that I need fixed is the “standard mouseclick attack”, or the parts in the server script that rely on a remoteEvent.
Now here are the problems. It has to do with both scripts. When I am waiting for the animation to end for the next animation to appear, the :Wait() signal refuses to connect. Even with Ended:Wait(), the same result happens. The next problem lies in the localScript. The .Button1Down fires, but .Button1Up also fires, which is not intentional.(This was when I was reusing the signal function for .Button1Up). The part in the LocalScript playerMouse.Button1Up:Wait() refuses to fire, and I do not understand what I can do to debug it. Even after I make the parts where there are 2 separate signal functions for Button1Up and Button1Down, they happen at the same time, allowing the player to spam click the tool, a result I do not want. I’ve even tried .Activated and .Deactivated but none even worked as a result in the serverScript.
Although a small problem, I do recognize its worth mentioning. I don’t know how to make it so that every swing, if the player has already swinged their melee weapon once but released their mouse early, the combo stops appearing.
However, I need the 2 main problems stated fixed. I don’t know what to do here. I don’t want to make it so that the player just uses 1 melee attack with the same animation 24/7 which is the point of the melee attack attacking multiple times when the player holds down their mouse.
If anyone would like to help, I’d greatly appreciate it. This is by far even more difficult than I thought to create.