#freezing an anim at the end

1 messages · Page 1 of 1 (latest)

brazen arrow
#

how do i freeze an animation at the end of it/at the last keyframe, local: ⁨`local uis = game:GetService("UserInputService")
local rs = game:GetService("ReplicatedStorage")
local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local hum = char:WaitForChild("Humanoid")
local rem = rs:WaitForChild("Remotes"):WaitForChild("testskillrem")

plr.CharacterAdded:Connect(function(newChar)
char = newChar
hum = char:WaitForChild("Humanoid")
end)

local cooldown = false

uis.InputBegan:Connect(function(inp, gpe)
if inp.KeyCode == Enum.KeyCode.Z and not gpe then
if cooldown then return end
cooldown = true

    rem:FireServer()

    task.wait(6)
    cooldown = false
end

end)`⁩

#

server:⁨` local rs = game:GetService("ReplicatedStorage")
local plrs = game:GetService("Players")
local rem = rs:WaitForChild("Remotes"):WaitForChild("testskillrem")
local debris = game:GetService("Debris")

rem.OnServerEvent:Connect(function(plr)
print("Skill fired by", plr.Name)
local char = plr.Character or plr.CharacterAdded:Wait()
local hum = char:WaitForChild("Humanoid")
local hrp = char:WaitForChild("HumanoidRootPart")

local Ogspeed = hum.WalkSpeed
hum.WalkSpeed = 0

local anim = Instance.new("Animation")
anim.AnimationId = "rbxassetid://135017096803352"
local track = hum:LoadAnimation(anim)
track.Priority = Enum.AnimationPriority.Action
track:Play()

local sound = rs.Sounds.TestSkillSound:Clone()
sound.Parent = hrp
sound:Play()

task.wait(1)

local hitbox = rs.Hitbox:Clone()
hitbox.Parent = workspace
hitbox.Anchored = true
hitbox.CanCollide = false
hitbox.CFrame = hrp.CFrame
debris:AddItem(hitbox, 0.5)

hitbox.Touched:Connect(function(hit)
    local enemyChar = hit:FindFirstAncestorOfClass("Model")
    local enemyHum = enemyChar and enemyChar:FindFirstChild("Humanoid")
    if enemyHum and enemyChar ~= char then
        enemyHum:TakeDamage(10)
    end
end)

task.wait(5)


track:Stop()
hum.WalkSpeed = Ogspeed
sound:Stop()

end)
`⁩

real vector
#

Use the adjust speed method

#

set it to 0 and bam

#

example: track:AdjustSpeed(0)

#

and to detect a last key frame I suggest adding animation events

brazen arrow
#

ok

#

thanks

real vector
#

then run the method

#

alternatively you can also get individual key frames using the key frame class, though it’s a bit tedious and requires a bit more coding

brazen arrow
#

alright so,

#

i tried to make it detect the last keyframe by the name, what im trying to achieve is that the animation is frozen until the sound finishes right? so i tried this and yet it dosent work

#

⁨`local rs = game:GetService("ReplicatedStorage")
local plrs = game:GetService("Players")
local rem = rs:WaitForChild("Remotes"):WaitForChild("testskillrem")
local debris = game:GetService("Debris")

rem.OnServerEvent:Connect(function(plr)
print("Skill fired by", plr.Name)
local char = plr.Character or plr.CharacterAdded:Wait()
local hum = char:WaitForChild("Humanoid")
local hrp = char:WaitForChild("HumanoidRootPart")

local Ogspeed = hum.WalkSpeed
hum.WalkSpeed = 0


local anim = Instance.new("Animation")
anim.AnimationId = "rbxassetid://135017096803352"
local track = hum:LoadAnimation(anim)
track.Priority = Enum.AnimationPriority.Action
track:Play()

local sound = rs.Sounds.TestSkillSound:Clone()
sound.Parent = hrp
sound:Play()


track.KeyframeReached:Connect(function(Framename)
    if Framename == "Last" then
        track:AdjustSpeed(0)
    end
end)


local hitbox = rs.Hitbox:Clone()
hitbox.Parent = workspace
hitbox.Anchored = true
hitbox.CanCollide = false
hitbox.CFrame = hrp.CFrame
debris:AddItem(hitbox, 0.5)

hitbox.Touched:Connect(function(hit)
    local enemyChar = hit:FindFirstAncestorOfClass("Model")
    local enemyHum = enemyChar and enemyChar:FindFirstChild("Humanoid")
    if enemyHum and enemyChar ~= char then
        enemyHum:TakeDamage(10)
    end
end)


sound.Ended:Connect(function()
    track:Stop()
    hum.WalkSpeed = Ogspeed
    sound:Stop()    
end)

end)`⁩

real vector
#

okay, give me a sec

#

i wouldn't recommend doing it like this, a lot of unused functions after

wanton magnet
real vector
#

make these functions local variables if you're planning on nesting them

#

disconnect them after you're done with operations

#

and instead of creating functions, you can use repeat wait() until sound.IsPlaying == false

#

or tie the :wait() function to an event

#

it's a bit hard to explain- though if you need an example i could help