#Reset value after x seconds?
11 messages · Page 1 of 1 (latest)
you can use delay/ task.delay (doenst stop the script while still running) or wait()/ task.wait() (stops the script till the time runs out)
There's no need to create a new thread. Just use math
thank you!
thank you sorry, didn't realise what that was for lol
when I tried this it just stopped the attacks from happening at all
I got this error
My bad. I wrote "combo" instead of "comboIndex". This should've shown a red underline in your script; you should've been able to debug this yourself, man
hmm odd, it's still letting me do the third attack even if I've waited like 5 seconds after doing the second attack
Show me your code
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local players = game:GetService("Players")
local Combo_Window = 0.25
local Combo_Max = 4
local comboIndex = 1
local comboTimestamp = 0
local Event = ReplicatedStorage:WaitForChild("Events") -- event is defined up here
local AttackHitBoxes = require(script.Parent.AttackHitboxes)
local ClickAttackDebounces = {}
--events doesnt exist XD
-- there we go
-- Changes 'Events' to 'Event' because 'Events' didn't exist and 'Event' was declared prior
local timestamp = time()
if comboIndex < Combo_Max and timestamp - comboTimestamp <= Combo_Window then
comboIndex += 1
else
comboIndex = 1
end
comboTimestamp = timestamp
Event.ClickAttack.OnServerEvent:Connect(function(Player)
local Character = Player.Character
if Character == nil then
return
end
local Humanoid = Character:FindFirstChild("Humanoid")
if Humanoid == nil then
return
end
if Humanoid.Health <= 0 then
-- if player health is equal to or greater than 0 = they aren't dead, continue the attack.
return
end
if ClickAttackDebounces[Player] then
return
end
ClickAttackDebounces[Player] = true
local PunchCombo = Player.Values.PunchCombo
local animation = script.PunchAnimationCycle[tostring(PunchCombo.Value)]
local LoadedPunchAnimation = Humanoid.Animator:LoadAnimation(animation)
LoadedPunchAnimation:Play()
if PunchCombo.Value >= #script.PunchAnimationCycle:GetChildren() then
PunchCombo.Value = 1
-- this is used to check what stage of the 4 click attack combo and then use that to figure out which attack we do next (counting up 1-4 and then resetting)
-- what are you trying to check here?
-- so the number of children punchanimationcycle has?
-- I believe so
-- well the error is occuring because when you GetChildren(), you return a TABLE of all the children an instance has
-- trying to check if a number is larger than a table doest make sense does it?
-- to get the length (number of things) of a table, put a # pound at the beginning
-- for example #part:GetChildren()
-- /|\
-- | its the # that means length of a table
else
PunchCombo.Value = PunchCombo.Value + 1
end
task.wait(LoadedPunchAnimation.Length + 0.1)
if ClickAttackDebounces[Player] then
ClickAttackDebounces[Player] = nil
end
end)