#Animation can be play but can't stopped?

66 messages · Page 1 of 1 (latest)

vast tree
#

Hello, i made a action button where if you press it will run a remote event and you will be playing animations inside the character that pressed the button (Roleplay Game)

I have a problem like I press the button and the animation it's works but
When i tried to press the button again the animation doesn't stop even thought everything was feel right, No any error tell in output or console

The Animation I put was Looped on, but i don't know if I use Anim:Stop() it would stop the animation or no

Hopefully anyone will help me on this, it's really important for me.

#
local on = false
game.ReplicatedStorage.MouthRemotes.CartoonCatNap.Lay.OnServerEvent:Connect(function(plr)
    local Character = plr.Character
    local Sprint = plr.Character.Sprint
    local LayAnimation = plr.Character.Humanoid:LoadAnimation(Character.Lay)
    local Humanoid = plr.Character.Humanoid

    if on == false then
        on = true
        LayAnimation:Play()
        Humanoid.WalkSpeed = 0
        Humanoid.JumpPower = 0
    else
        LayAnimation:Stop()
        Humanoid.WalkSpeed = 16
        Humanoid.JumpPower = 80
        on = false
    end
end)
#

I have grammar issue don't mind me btw

shut furnace
#

you are defining the animation when you fire the event
you cannot stop another animation that is playing

like, you try to stop the animation, but an existing one already plays

shut furnace
#

change speed/jump on server

vast tree
#

hm but can the other player see the animations too?

vast tree
vast tree
# shut furnace yes

what should i do to make it play animation with button?

local on = false
script.Parent.MouseButton1Click:Connect(function(plr)
    local Character = plr.Character
    local Sprint = plr.Character.Sprint
    local LayAnimation = plr.Character.Humanoid:LoadAnimation(Character.Lay)
    local Humanoid = plr.Character.Humanoid
    game.ReplicatedStorage.MouthRemotes.CartoonCatNap.Lay:FireServer()
    
    if on == false then
        on = true
        LayAnimation:Play()
    else
        LayAnimation:Stop()
        on = false
    end
end) 
shut furnace
#

remove plr from function

#

instead do
local plr = game.Players.LocalPlayer
local LayAnimation = plr.Character.Humanoid:LoadAnimation(Character.Lay)
before the function

#
local on = false
  local plr = game.Players.LocalPlayer
  local Character = plr.Character
    local Sprint = plr.Character.Sprint
    local LayAnimation = plr.Character.Humanoid:LoadAnimation(Character.Lay)
    local Humanoid = plr.Character.Humanoid
script.Parent.MouseButton1Click:Connect(function()
    game.ReplicatedStorage.MouthRemotes.CartoonCatNap.Lay:FireServer()
    
    if on == false then
        on = true
        LayAnimation:Play()
    else
        LayAnimation:Stop()
        on = false
    end
end) 
#

mousebutton1click does not pass the player

vast tree
#

this is ok right

shut furnace
#

there

#

fixed

vast tree
#

Ok lemme try

verbal carbon
#

win + L to fix

vast tree
#

i think i do have humanoid here

shut furnace
#
local on = false
  local plr = game.Players.LocalPlayer
repeat task.wait() until game:IsLoaded()
  local Character = plr.Character
    local Sprint = Character.Sprint
    local LayAnimation = Character:WaitForChild("Humanoid"):WaitForChild("Animator"):LoadAnimation(Character.Lay)
    local Humanoid = Character.Humanoid
script.Parent.MouseButton1Click:Connect(function()
    game.ReplicatedStorage.MouthRemotes.CartoonCatNap.Lay:FireServer()
    
    if on == false then
        on = true
        LayAnimation:Play()
    else
        LayAnimation:Stop()
        on = false
    end
end) 
#

it executes the script before the game loads

#

that's whyt

vast tree
shut furnace
#

try this

vast tree
shut furnace
#
local on = false
  local plr = game.Players.LocalPlayer
repeat task.wait() until game:IsLoaded()
  local Character = plr.Character
    local Sprint = Character.Sprint
    local LayAnimation = Character:WaitForChild("Humanoid"):WaitForChild("Animator"):LoadAnimation(Character:WaitForChild("Lay")
    local Humanoid = Character.Humanoid
script.Parent.MouseButton1Click:Connect(function()
    game.ReplicatedStorage.MouthRemotes.CartoonCatNap.Lay:FireServer()
    
    if on == false then
        on = true
        LayAnimation:Play()
    else
        LayAnimation:Stop()
        on = false
    end
end) 
vast tree
shut furnace
#

can you send me how your script looks like

vast tree
#
local on = false
local plr = game.Players.LocalPlayer
repeat task.wait() until game:IsLoaded()
local Character = plr.Character
local Sprint = Character.Sprint
local LayAnimation = Character:WaitForChild("Humanoid"):WaitForChild("Animator"):LoadAnimation(Character:WaitForChild("Lay")
local Humanoid = Character.Humanoid
script.Parent.MouseButton1Click:Connect(function()
    game.ReplicatedStorage.MouthRemotes.CartoonCatNap.Lay:FireServer()

    if on == false then
        on = true
        LayAnimation:Play()
    else
        LayAnimation:Stop()
        on = false
    end
end) ```
shut furnace
#

in studio

vast tree
shut furnace
#

bruhhh

#

how the script looks in the studio

#

not in workspace

vast tree
#

o wait

#

i has custom theme

shut furnace
#

remove ( before Character on line 6

#
local on = false
local plr = game.Players.LocalPlayer
repeat task.wait() until game:IsLoaded()
local Character = plr.Character
local Sprint = Character.Sprint
local LayAnimation = Character:WaitForChild("Humanoid"):WaitForChild("Animator"):LoadAnimation(Character:WaitForChild("Lay"))
local Humanoid = Character.Humanoid
script.Parent.MouseButton1Click:Connect(function()
    game.ReplicatedStorage.MouthRemotes.CartoonCatNap.Lay:FireServer()

    if on == false then
        on = true
        LayAnimation:Play()
    else
        LayAnimation:Stop()
        on = false
    end
end) 
#

or nvm

#

this

#

i forgot to add 1 bracket at te end

shut furnace
#
task.wait(0.25)
local on = false
local plr = game.Players.LocalPlayer
repeat task.wait() until game:IsLoaded()
local Character = plr.Character
local Sprint = Character.Sprint
local LayAnimation = Character:WaitForChild("Humanoid"):WaitForChild("Animator"):LoadAnimation(Character:WaitForChild("Lay"))
local Humanoid = Character.Humanoid
script.Parent.MouseButton1Click:Connect(function()
    game.ReplicatedStorage.MouthRemotes.CartoonCatNap.Lay:FireServer()

    if on == false then
        on = true
        LayAnimation:Play()
    else
        LayAnimation:Stop()
        on = false
    end
end) 
#

try to add a wait (like i did here) before the script

vast tree
unborn finchBOT
#

studio** You are now Level 5! **studio

shut furnace
#

make wait more then

#

like 0.5

#
local on = false
local plr = game.Players.LocalPlayer
repeat task.wait() until game:IsLoaded()
local Character = plr.Character
local Sprint = Character.Sprint
local LayAnimation
local Humanoid = Character.Humanoid
script.Parent.MouseButton1Click:Connect(function()
    if not LayAnimation then
         LayAnimation = Character:WaitForChild("Humanoid"):WaitForChild("Animator"):LoadAnimation(Character:WaitForChild("Lay"))
    end
    game.ReplicatedStorage.MouthRemotes.CartoonCatNap.Lay:FireServer()

    if on == false then
        on = true
        LayAnimation:Play()
    else
        LayAnimation:Stop()
        on = false
    end
end) 

actually try this

shut furnace
#
local on = false
local plr = game.Players.LocalPlayer
repeat task.wait() until game:IsLoaded()
local Character = plr.Character
local Sprint = Character.Sprint
local LayAnimation

script.Parent.MouseButton1Click:Connect(function()
    if not LayAnimation then
local Humanoid = Character.Humanoid
         LayAnimation =   Character:WaitForChild("Humanoid"):WaitForChild("Animator"):LoadAnimation(Character:WaitForChild("Lay"))
    end
    game.ReplicatedStorage.MouthRemotes.CartoonCatNap.Lay:FireServer()

    if on == false then
        on = true
        LayAnimation:Play()
    else
        LayAnimation:Stop()
        on = false
    end
end) 
#

try this

vast tree
shut furnace
#
local on = false
local plr = game.Players.LocalPlayer
repeat task.wait() until game:IsLoaded()
local Character = plr.Character
local Sprint = Character.Sprint
local LayAnimation

script.Parent.MouseButton1Click:Connect(function()
    if not LayAnimation then
local Humanoid = plr.Character.Humanoid
         LayAnimation =   plr.Character:WaitForChild("Humanoid"):WaitForChild("Animator"):LoadAnimation(Character:WaitForChild("Lay"))
    end
    game.ReplicatedStorage.MouthRemotes.CartoonCatNap.Lay:FireServer()

    if on == false then
        on = true
        LayAnimation:Play()
    else
        LayAnimation:Stop()
        on = false
    end
end) 
#

idk man

vast tree
#

Idk too 💀 ig i can't do it

shut furnace
#

you can but your code is kinda messy i guess

vast tree
#

i don't really know what should i do

shut furnace
#

ask chat gpt or something