I’m creating an emote wheel, and there is currently one emote available. When I use the emote and cancel it using the spacebar the first time, it cancels the animation. But the second time I try to cancel it, the animation doesn’t stop. I’m able to move again, but the animation is still playing.
Here’s the script:
local UserInputService = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local char = script.Parent
local hum = char:WaitForChild("Humanoid")
local animator = hum:WaitForChild("Animator")
local emoteAnim = script.Parent:WaitForChild("EmoteAnim")
local isEmoting = false
local emoteTrack = nil
local function startAnimation(animID: string)
emoteAnim.AnimationId = animID
emoteTrack = animator:LoadAnimation(emoteAnim)
ReplicatedStorage.CloseEmoteWheel:Fire()
isEmoting = true
emoteTrack.Looped = true
emoteTrack:Play()
hum.WalkSpeed =0.0075
hum.JumpPower = 0
end
ReplicatedStorage.EmoteEvent.Event:Connect(function(anim)
startAnimation(anim)
UserInputService.InputBegan:Connect(function(i, gpe)
if i.KeyCode == Enum.KeyCode.Space and not gpe and isEmoting == true then
isEmoting = false
print("Canceled: " .. anim)
emoteTrack:Stop()
emoteTrack:Destroy()
emoteAnim.AnimationId = ""
print(tostring(emoteTrack))
hum.WalkSpeed = 16
hum.JumpPower = 50.145
end
end)
end)