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

How to make an animation continue until something happens?

Asked by 5 years ago
local animation = Instance.new("Animation")
animation.AnimationId = "http://www.roblox.com/Asset?ID="..animationID
kame = true
local loadedAnimation = Player.Character.Humanoid:LoadAnimation(animation)
repeat
    loadedAnimation:Stop()
    loadedAnimation:Play()
    wait() 
until 
    kame == false

The player holds the animation but after some time he just stops it and has the standing animation. When he stops it out of nothing the variable kame is still true.

0
`.Looped` property EpicMetatableMoment 1444 — 5y

2 answers

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

Question

How to make an animation continue until something happens?

Answer

There is a .Looped property for AnimationTrack's. We can set it to true to have the track continue looping after its been played.

Click "Accept Answer" if this helped.

Example

local players = game:GetService("Players") --// define players service

local client = players.LocalPlayer --// get client (local player)
local character = client.Character or client.CharacterAdded:Wait() --// get character
local humanoid = character:WaitForChild("Humanoid") --// get humanoid

local animationID = ... --// assumed reference to your animation id
local kame = ... -// assumed reference to your `kame` boolean. 


local animation = Instance.new("Animation") --// create new animation

animation.AnimationId = ("rbxassetid://%s"):format(animationID) --// define animationId

local animationTrack = humanoid:LoadAnimation(animation) --// load track
animationTrack.Looped = true --// set track to looped so it keeps replaying. 

kame = true --// set `kame` to true because we are using it 
animationTrack:Play() --// play animation track

repeat wait() until not kame --// keep yielding thread until `kame` is false. 
animationTrack:Stop() --// stop animation because `kame` is now false. 
Ad
Log in to vote
0
Answered by 5 years ago

Example 1:

Run from a (Server) Script

local player = game.Players.LocalPlayer
local animation = Instance.new("Animation", script)
local check = Instance.new("BoolValue", script)

animation.AnimationId = "rbxassetid://0"
workspace:WaitForChild("player.Name")
local loadedAnimation = player.Character.Humanoid:LoadAnimation(animation)

while true do
    if check.Value == false then
        loadedAnimation:Play()
        wait(2)
    else
        wait()
    end
end

Notes

  1. Line 3: Set this to the id number of the animation (you MUST own it)

  2. Line 12: The number in the wait(#) should be the amount of time the animation runs for (default of 2)

Explanation: your "kame" acts as a debounce, but by using the repeat until event, you are unable to replay the loop after kame is changed. (although in your script, it never does?) You also never set the animation id number, so you'll need to add that to the script. Setting the BoolValue added above to true will cause the animation to stop, and you could also restart it later.

Example 2:

Run from a (Server) Script

local player = game.Players.LocalPlayer
local animation = Instance.new("Animation", script)

animation.AnimationId = "rbxassetid://0"
workspace:WaitForChild("player.Name")
local loadedAnimation = player.Character.Humanoid:LoadAnimation(animation)
loadedAnimation.Looped = true

repeat
    loadedAnimation:Play()
    wait(2)
until loadedAnimation.Looped = false

Notes: Same As Above

Explanation: The looped property of the animationtrack will allow you to play the animation continuously. All you have to do is make a function set the looped property to false and the animation will end.

Answer this question