I’ve created a simple GUI system with dances. The only issue i have is, when i select a dance , i can select another one without stopping the first one. I searched on Dev Forum, Dev Hub and Youtube and i couldn’t find anything. Is there a way to stop a dancing animation when playing a different one?
local player = game.Players.LocalPlayer
local character = player.Character
repeat wait()
character = player.Character
until character
local hum = character:WaitForChild("Humanoid")
local emote = hum:LoadAnimation(script.Parent.Emote)
playing = false
script.Parent.MouseButton1Click:connect(function()
if playing == false then
emote:Play()
hum.WalkSpeed = 0
hum.JumpPower = 0
playing = true
elseif playing == true then
emote:Stop()
hum.WalkSpeed = 16
hum.JumpPower = 50
playing = false
end
end)
Each button has this script in it and i know when i stop an emote from playing the WalkSpeed and the JumpPower will go back to their normal values, even if there is another animation playing, which is why i want for all the animations to stop when playing a new one.
At first i wanted to do a script with all the dances Emote defined and when a specified emote is playing, the other ones will stop but realised that this will take a lot of time, since i plan on adding many more dances in the future.
Note that i am a beginner scripter and i might not know all the ways (harder or not) possible to do that
Not sure if you have fixed this, but I would suggesting using a variable like prev
Declare a local prev
and every time the animation is changed, if prev is not nil then prev:Stop() animation. Then, play the new animation, and set the prev variable to the new animation that was just played.
Can you give me an example? I am still new to scripting so i don’t know most of the things. I just understood how ContextAction works and i thought that would work.
Edit : I think i got it, i am looking on DevHub and i saw Humanoid.Changed. Thank you so much . I might reply again if i have an issue that i cannot find a solution.
@jimbot220
Alright so i did as it told me and here is where i got stuck. The animation stops when a player jumps but it doesn’t stop when the player moves. I tried both with Running and RunningNoPhysics.
hum.StateChanged:Connect(function(jumpState , runState)
if jumpState == Enum.HumanoidStateType.Jumping then
emote:Stop()
playing = false
elseif runState == Enum.HumanoidStateType.Running then
emote:Stop()
playing = false
end
end)
The two parameters of the function can be named however you want as long as you use them correctly. As i said, the animation stops when i jump but it doesn’t stop when i run. I am trying to make so when a player moves/jumps, the dancing animation he is currently playing will stop, @No_b2. But thank you for that advise.