I made a punch script and for some odd reason, with no errors, the punch script only does a Left Punch, and it's spammable if I didn't put in the cooldown in the local script. Here's the server sided.
local PunchEvent = game.ReplicatedStorage.punch
local Cooldown = 0.4
local PunchData = {}
local function PlaySound(ID,Parent)
local Sound = Instance.new("Sound")
Sound.SoundId = "rbxassetid://"..ID
Sound.PlayOnRemove = true
Sound.Parent = Parent
Sound:Destroy()
end
local torw = 711753382
PunchEvent.OnServerEvent:Connect(function(Player)
local Character = Player.Character
while Character.Parent == nil do
wait()
end
local Humanoid = Character:WaitForChild("Humanoid")
local Animator = Humanoid:WaitForChild("Animator")
PunchData[Player] = {
["LeftPunch"] = Animator:LoadAnimation(script.Left),
["RightPunch"] = Animator:LoadAnimation(script.Right),
["LastPunch"] = "LeftPunch",
["CanPunch"] = true
}
local SecondaryDataTable = PunchData[Player]
local RightHand = Character.RightHand
local LeftHand = Character.LeftHand
local CurrentConnection = nil
local CurrentAnimationTrack = nil
if SecondaryDataTable.CanPunch then
if SecondaryDataTable.LastPunch == "LeftPunch" then
SecondaryDataTable.CanPunch = false
PlaySound(711753382, Character.RightHand)
CurrentAnimationTrack = SecondaryDataTable.RightPunch
CurrentConnection = Character.RightHand.Touched:Connect(function(Hit)
local Humanoid = Hit.Parent:FindFirstChildOfClass("Humanoid")
if Humanoid then
Humanoid:TakeDamage(12)
PlaySound(367499850, RightHand)
CurrentConnection:Disconnect()
end
end)
SecondaryDataTable.LastPunch = "RightPunch"
elseif SecondaryDataTable.LastPunch == "RightPunch" then
SecondaryDataTable.CanPunch = false
PlaySound(711753382, LeftHand)
CurrentAnimationTrack = SecondaryDataTable.LeftPunch
CurrentConnection = Character.LeftHand.Touched:Connect(function(Hit)
local Humanoid = Hit.Parent:FindFirstChildOfClass("Humanoid")
if Humanoid then
Humanoid:TakeDamage(12)
PlaySound(367499850, LeftHand)
CurrentConnection:Disconnect()
end
end)
SecondaryDataTable.LastPunch = "LeftPunch"
end
CurrentAnimationTrack:Play()
CurrentAnimationTrack.Stopped:Wait()
if CurrentConnection then CurrentConnection:Disconnect() end
wait(Cooldown)
SecondaryDataTable.CanPunch = true
end
end)
And here's the local script.
local Player = game.Players.LocalPlayer
repeat wait() until Player.Character
local Mouse = Player:GetMouse()
local PunchEvent = game.ReplicatedStorage.punch
local TakeStamina = game.ReplicatedStorage.TakeStamina
local Data = Player.Data
local Stamina = Data.Stamina
local Debounce = false
Mouse.Button1Down:Connect(function()
if Stamina.Value > 11 then
if not Debounce then
Debounce = true
PunchEvent:FireServer()
TakeStamina:FireServer(10)
wait(0.4)
Debounce = false
end
end
end)

2 comments
connect is deprecated use Connect
Edited.