#Improper stun reset?

1 messages · Page 1 of 1 (latest)

fallen pendant
#

So this is my server side script and I think that a new timer is created every time the player is hit, which I do not want. I want only 1 timer per hit and if they are hit again get rid of that old timer. Im kinda stumped.

primal yew
#

look at your else statements

#

they dont make sense

#

do

if -- then

elseif then

else

end

#

and so on

fallen pendant
#

really? It seemed to work fine for me, maybe the structure is just funky. Unless it is wrong.

primal yew
#

it just makes it sloppy n shi

fallen pendant
wind glacierBOT
#

studio** You are now Level 1! **studio

fallen pendant
#

Though do u happen to know how to have only 1 stun timer per event?

primal yew
#
local KickEvent = game.ReplicatedStorage:WaitForChild("Kick")

local debris = game:GetService("Debris")

local dmg
local force
local upward

local stuntimer = 2

local function pushback(plrhrp, hrp, pushforce, upward)
    local bv = Instance.new("BodyVelocity")
    bv.P = 2000
    bv.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
    bv.Velocity = plrhrp.CFrame.LookVector * pushforce + Vector3.new(0, upward, 0)
    bv.Parent = hrp
    debris:AddItem(bv, 0.4)
end

KickEvent.OnServerEvent:Connect(function(plr, victim, combo)


    local victimchar = victim.Parent
    local victimhrp = victimchar:WaitForChild("HumanoidRootPart")
    local plrchar = plr.Character
    local plrhrp = plrchar:WaitForChild("HumanoidRootPart")


    task.spawn(function()
        while true do
            stuntimer -= 0.1
            if stuntimer >= 0 then
                victimchar:SetAttribute("Stunned", true)
                print("stunned")
            else
                victimchar:SetAttribute("Stunned", false)
                print("Not Stunned")
                stuntimer = 2
                break
            end
            wait(0.1)
        end
    end)


    -- Blocking check
    if victimchar:GetAttribute("Blocking") == true then
        combo = 3
        force = 50
        upward = 15
        stuntimer = 2
        pushback(plrhrp, victimhrp, force, upward)
        victimchar:SetAttribute("Blocking", false)

    elseif combo == 3 then
        force = 50
        upward = 15
        pushback(plrhrp, victimhrp, force, upward)
        stuntimer = 2

    else
        force = 5
        upward = 0
        pushback(plrhrp, victimhrp, force, upward)
        stuntimer = 2
        victimchar:TakeDamage(10)
    end
end)
primal yew
#

and then like

#

time - 0 < coolDownTime or something idfk

#

and then updated time = time()

#

¯_(ツ)_/¯

#

wait im slow sorry

fallen pendant
#

ok ty, I'll try time(), I knew it was probably the better way to go than the way I did but I don't know how to implement it yet so I thought making a variable go down like that would suffice lol

primal yew
#

is it like a one time ability?

#

or just a cooldown thing

primal yew
fallen pendant
#

Cooldown thing i think, would u like to see the client code? Also yea an example would be nice

primal yew
#

aight sec

#
local coolDown = 0.7
    local lastSlashTime = 0
     bulletEventConnection = shootBullet.OnClientEvent:Connect(function()
        local currentTime = time()
        local withinCooldown = currentTime - lastSlashTime < coolDown
        lastSlashTime = currentTime

        if withinCooldown then
            slash1 = not slash1
        else
            slash1 = false
        end
#

this is just a snippet of something

fallen pendant
#

K ima analyze for a sec cause my brain going blank lol

primal yew
#

okay : D

#

If the time (seconds) since the last action is less than cooldown, then do blah blah

fallen pendant
#

does the if statement for withincooldown always make slash1 false?

primal yew
#

you can ignore that

#

think abt like this

#

if within cooldown then (in your case) do nothing?

#

probably by using a debounce

fallen pendant
#

srry, Im still trying to grasp the logic behind the timing

primal yew
#

"if cooldown passed then can do ActionDebounce = true" that kinda logic

fallen pendant
#

but yea do nothing in my case

#

Ok i'll try giving it a go on my code

primal yew
primal yew
#

i hope i didnt confuse you 💔