So I was making a combat system where you have a m1 combo and other stuff. I added a condition when player will get stun or burn or something. So when player got hit, they’ll be stunned for a second. I added task.wait(seconds) to complete the function, but the problem is they do overlapping. There’s only one way I can do is subtracting a current tick and unupdated tick and check if the differences is more than a second, then it will set stun to false. In order to do that. I need to use a loop for this, I think it’s little bit messy. I want to know if there are other methods I can do for this.
Condition ModuleScript:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ClassifyModule = require(ReplicatedStorage.Modules.Classify)
local Data = require(ReplicatedStorage.Modules.Data)
local stunTick = {}
local module = {}
module.__index = module
function module.New(State,Condition,CharacterToSet : Model)
local moduleParameters = {
["State"] = State,
["Condition"] = Condition,
["CharacterToSet"] = CharacterToSet
}
function module:Stun(seconds : number)
local Condition = self.Condition
local CharacterToSet = self.CharacterToSet
stunTick[CharacterToSet] = tick()
ClassifyModule.SetValue(Condition.Condition.Stun,true)
while task.wait() do -- This is where i want to change
if tick() - stunTick[CharacterToSet] >= seconds then
ClassifyModule.SetValue(Condition.Condition.Stun,false)
end
end
end
function module:BlockBreak(stun)
if stun then module:Stun() end
end
return setmetatable(moduleParameters,module)
end
return module
Classify ModuleScript:
local module = {}
function module.GetSameStringForObject(thisValue : string?,from : Instance)
for _,v in pairs(from:GetChildren()) do
if thisValue == v.Name then
return v
end
end
end
function module.SetValue(object:Instance,value:ValueBase)
object.Value = value
end
return module
Any more method or solutions?