Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How can I delay a lot of function calls and execute them all at once once a condition is met?

Asked by
9bi7 0
5 years ago
Edited 5 years ago

Ok, so long story short, I'm trying to make a time stop function. I have no problem registering the hits, or dealing the damage, but when it comes to dealing damage after a timestop, the calls of the damage function are a problem. My current solution, while rudimentary, isn't as fast as I'd like it to be and it isn't very reliable either. I mean, it does the damage, but not even in the right order. Here is an example of what I mean. The damage should be applied instantly to all of the dummies (or at least quicker than it is already), going down the row from left to right. Instead, this is what happens: gyazo I won't post my code in detail because that isn't the focus of this question. I will replace it with some comments instead.

hitevent.OnServerInvoke = function(player, id, hitter, hittercframe, damage, voiceline, hum)
    local hit = false
    --finds a suitable humanoid within a region which is cast by the server


    local registered = false
    if hum and hum.Health > 0 and registered == false then
        registered = true
        hit = true
        if game.Workspace.timestopped.Value == true then --this is the condition i want to be met
            coroutine.resume(coroutine.create(function()
                repeat wait() until game.Workspace.timestopped.Value == false
                    coroutine.resume(coroutine.create(function()
                        applydamage(player,id, hittercframe, hum, damage)
                    end))
            end))
        else
        applydamage(player, id, hittercframe, hum, damage)
    end
    return hit
end

The problem is stacking all the damage calls at once. I even tried with two coroutines as you can see, and the problem still persists. I'm not sure if wait() is not precise enough or what, but as you can see from the gif, I can't keep it like this. Thank you for any help.

0
When you've done checks for a humanoid, don't apply the damage yet. Instead, add the person to a list of people to be damaged. Afterwards, wrap a loop through that table inside of your repeat. There shouldn't be need for a coroutine, since (based on the gyazo you sent) application of damage is be near instantaneous. saenae 318 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

Here's an idea I came up with:

local CallCount = 0
local TimeStopped = workspace.timestopped

function Print()
    print("Test")
end

script.Parent.MouseClick:Connect(function(player)
    CallCount = CallCount + 1
    if TimeStopped.Value == true then 
        for i = 0, CallCount do 
            Print()
        end
    end
end)
Ad

Answer this question