#best way to handle stunning people
1 messages · Page 1 of 1 (latest)
How is task wait being messy
Show code
okay hold on
while its booting up
the problem is
is that lets say i have 2 waits
one wait may finish and unstun before the other wait is finished
meaning it unstuns when i dont want it to
which is obviously bad
okay let me get the code rq
So why u stunning twice
cuz of other moves happening at the same time
like m1s
thats 4 stuns happening in quick succession
local module = {}
function module.Stun(char : Model, timecantunstun : number, timestun : number)
char:SetAttribute("Stunned", true)
char:SetAttribute("CanUnstun", false)
task.wait(timecantunstun)
char:SetAttribute("CanUnstun", true)
task.wait(timestun)
if char:GetAttribute("CanUnstun") == false then return end
char:SetAttribute("Stunned", false)
end
return module
Tbf if I was in this situation I'd just have variable in module that is stunned[per] and is set to Unix timestamp
whats that?
With repeat untill rn is the unix
Unix is number of seconds since 1970
Basically u can save time
so i should use repeat loops?
Actually might be better way
I am thinking if not while loop with task wait wouldn't be better
As in
while true do
now = os.clock()
task.wait(stunned[plr]-now)
If stunned[plr] <= now then
Unstunne
End
end
this seems good
okay ill try it out in a bit
Just don't run the loop more then once
If u add stun time while stunned it should be fine
Shouldnt have the problem u got
alr ill log in here how this goes
can you go more in detail with this? ive been trying to figure this out for a few days and well im not really getting anywhere
local stunned = {}
function stun(player,duration)
if ISNT STUNNED (your logic here) then
stunned[player] = (stunned[player] or os.clock()) + duration
while true do
task.wait(stunned[player]-os.clock())
if os.clock() >= stunned[player}:
unstunne
stunned[player] = nil
break
end
else
-- is stunned
stunned[player] += duration
end
end
maybe smth like this
sorry for format but i wrote it on discord
okay ill try this out
thank you
i managed to get it working. tysm
What method u used