How can I perfectly time out functions on cutscenes/animations

How would I timeout functions for animations/cutscenes like damaging a player during a certain amount of time. For example:

In Roblox Lua, you can use the wait() function to implement timeouts for animations or cutscenes. Here’s an example of how you can use it to damage a player after a certain amount of time:

-- Function to damage the player
local function damagePlayer(player)
    -- Implement your damage logic here
    print(player.Name .. " has been damaged!")
end

-- Timeout function
local function timeoutFunction(player)
    wait(5) -- Wait for 5 seconds (adjust the time as needed)

    -- Check if the player is still valid (e.g., not left the game)
    if player and player:IsDescendantOf(game.Players) then
        damagePlayer(player)
    end
end

-- Example usage
local playerToDamage = game.Players.LocalPlayer -- Replace this with the desired player

-- Call the timeout function
timeoutFunction(playerToDamage)

In this example, the timeoutFunction waits for 5 seconds using the wait() function. After the specified time has passed, it checks if the player is still valid (i.e., hasn’t left the game) and then calls the damagePlayer function if the player is still present.

You can adjust the timeout duration and modify the damagePlayer function according to your specific requirements.

Use animation events to do this.
With animation events you can set the time of the function directly through the animation editor which is best for precise timing on stuff like this.

If you want an example rbxl on how to get it to work, let me know.

Also, don’t listen to @ikDebris, as wait() is very inaccurate for this stuff.
I’m pretty sure that response is AI generated anyway.

Does moon animator have this feature? If you have ever used it

It might not, but when you are publishing the animation you use the built in editor right?
Or are you not publishing the animations?

Yeah, I could just use the built in animator. Can you use GetMarkerReachedSignal function inside of a serverscript, if not that will make my job so much harder.

If the client is playing it then you’ll have to use it from the client, otherwise it should work on the server.

Alright, Ill play around with it, thanks for the help!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.