Hi so I’m making a combo punch script using region3 for my RPG and I ran into this issue where I need to make it so if the player hasn’t punched for 1 second, the combo goes back to 1 and the player has to wait 1 second.
Does anyone know how I can do this?
Here’s the script
local RunService = game:GetService("RunService")
local Enabled = true
local Combo = 1
local Region
local RTable
local run = false
local punchdamage = 4
local regionsize = -1.5
script.Parent.OnServerEvent:connect(function(Player, Action)
local c = Player.Character
if Enabled == false then return end
if Action == "Combat" then
local Anim1 = c.Humanoid:LoadAnimation(script.Punch1)
local Anim2 = c.Humanoid:LoadAnimation(script.Punch2)
local Anim3 = c.Humanoid:LoadAnimation(script.Punch3)
local Anim4 = c.Humanoid:LoadAnimation(script.Punch4)
local S1 = script.p1
local S2 = script.p2
local S3 = script.p3
Enabled = false
if Combo == 1 then
Combo = 2
Anim1:Play()
script.Event:Fire()
elseif Combo == 2 then
Combo = 3
Anim2:Play()
script.Event:Fire()
elseif Combo == 3 then
Combo = 4
Anim3:Play()
script.Event:Fire()
elseif Combo == 4 then
Combo = 1
Anim4:Play()
script.Event:Fire()
end
wait(.05)
coroutine.resume(coroutine.create(function()
while RunService.Stepped:Wait() and Anim1.IsPlaying or Anim2.IsPlaying or Anim3.IsPlaying or Anim4.IsPlaying do
Region = Region3.new(c.HumanoidRootPart.CFrame*CFrame.new(0,0,regionsize).p - Vector3.new(2,2,2),c.HumanoidRootPart.CFrame*CFrame.new(0,0,regionsize).p + Vector3.new(2,2,2)) -- region3
RTable = workspace:FindPartsInRegion3(Region, nil, 20) -- findpartsinregion
for i,v in pairs(RTable) do
if v.Parent:findFirstChild("Humanoid") and v.Parent:findFirstChild("Deb") == nil and v.Parent ~= c then
run = true
end
end
if run == true then
run = false
break
end
end
for i,v in pairs(RTable) do
RTable = false
if v.Parent:findFirstChild("Humanoid") and v.Parent:findFirstChild("Deb") == nil and v.Parent ~= c then
v.Parent.Humanoid:TakeDamage(punchdamage) -- takedamage
local Deb = Instance.new("BoolValue", v.Parent)
Deb.Name = "Deb"
game.Debris:AddItem(Deb,0.1)
S1.PlaybackSpeed = math.random(80,120)/100
S1:Play()
end
end
end))
wait(.2)
Enabled = true
if c.Humanoid.Health < 1 then
script.Parent.Parent:Destroy()
end
end
end)