#My animation don't stop at the time i say to stop (i used Chat-gpt)

1 messages · Page 1 of 1 (latest)

coarse flame
#

my thoughts: when i click a button (mousebutton1) it will start the animation and will stop the animation at the end, then when i click te button again it will be turn in to normal.
the bug is: the player goes back to normal without the second click
extra information: I speak Portuguese, so some parts of the script are written in Portuguese

#
local UserInputService = game:GetService("UserInputService")
local Players = game:GetService("Players")
local player = Players.LocalPlayer

local poseAnimation = Instance.new("Animation")
poseAnimation.AnimationId = "rbxassetid://95827014638144"

local poseTrack
local isPosing = false

local function setupAnimation()
    local character = player.Character or player.CharacterAdded:Wait()
    local humanoid = character:WaitForChild("Humanoid")
    poseTrack = humanoid:LoadAnimation(poseAnimation)
    poseTrack.Priority = Enum.AnimationPriority.Action
    poseTrack.Looped = false
end

setupAnimation()
player.CharacterAdded:Connect(setupAnimation)

UserInputService.InputBegan:Connect(function(input, gameProcessed)
    if gameProcessed then return end
    if input.UserInputType == Enum.UserInputType.MouseButton1 and poseTrack then
        if not isPosing then
            poseTrack:Play()

            -- Congela quando chegar perto do final
            task.delay(poseTrack.Length, function()
                if poseTrack.IsPlaying then
                    poseTrack:AdjustSpeed(0) -- congela na última posição
                end
            end)

            isPosing = true
        else
            -- Faz voltar ao normal
            poseTrack:Play()
            poseTrack.TimePosition = poseTrack.Length
            poseTrack:AdjustSpeed(-1)

            task.wait(poseTrack.Length)
            poseTrack:Stop()
            poseTrack:AdjustSpeed(1)

            isPosing = false
        end
    end
end)
#

that script is a poop? or chat-gpt did "right"?

#

the code just not stop in the position that i want, i think i just need to put a code that GPT don't know

devout nebula
#

By button you mean your mouse?

pastel finchBOT
#

studio** You are now Level 1! **studio

coarse flame
#

yes

#

left mouse click

devout nebula
#

Bro whats is ts 😭

coarse flame
#

ts?

#

too simple?😳

coarse flame
devout nebula
#

You are making it so that if it isint playing then start playing it and after that you wait the lenght of the animation and freeze it. But if it is playing and you clicked then it STILL STARTS PLAYING IT then waits the whole track lenght again?

#

Ion know what the adjust speed -1 should do tho

coarse flame
#

... im using the translator sorryrizz, one second

pastel finchBOT
#

studio** You are now Level 1! **studio

devout nebula
#

Do you want it to stop entirely or to freeze it ?

coarse flame
#

stop at the end of the animation

devout nebula
#

And freeze it normaly?

coarse flame
#

the "player" will still walk normaly

#

with the animation

#

what do you mean with "freeze it normaly"? the character can't move in that situation?

devout nebula
#

I mean the animation

coarse flame
#

yes, the animation will still be freezed until i click again

devout nebula
#
local UserInputService = game:GetService("UserInputService")
local Players = game:GetService("Players")
local player = Players.LocalPlayer

local poseAnimation = Instance.new("Animation")
poseAnimation.AnimationId = "rbxassetid://95827014638144"

local poseTrack
local isPosing = false

local function setupAnimation()
    local character = player.Character or player.CharacterAdded:Wait()
    local humanoid = character:WaitForChild("Humanoid")
    poseTrack = humanoid:LoadAnimation(poseAnimation)
    poseTrack.Priority = Enum.AnimationPriority.Action
    poseTrack.Looped = false
end

setupAnimation()
player.CharacterAdded:Connect(setupAnimation)

UserInputService.InputBegan:Connect(function(input, gameProcessed)
    if gameProcessed then return end
    if input.UserInputType == Enum.UserInputType.MouseButton1 and poseTrack then
        if not isPosing then
            poseTrack:Play()

            -- Congela quando chegar perto do final
            task.delay(poseTrack.Length - poseTrack.TimePosition, function()
                if poseTrack.IsPlaying and isPosing then
                   poseTrack:Stop()
                end
            end)

            isPosing = true
        else
            -- Faz voltar ao normal
            poseTrack:Pause()
            --poseTrack:AdjustSpeed(-1)
            isPosing = false
        end
    end
end)
coarse flame
#

done?????!?!?!?!?!?

devout nebula
#

Idk much about animations and im on a phone so i cant really like see it

#

Maybe

#

You instead want to pause the animation

coarse flame
#

trying

devout nebula
#

Instead of playing it again the second tims

coarse flame
#

PlayPoseOnClick:38: Pause is not a valid member of AnimationTrack "Animation"

devout nebula
#

Uhh replace it with Stop

coarse flame
#

i do that

devout nebula
#

Wait no

coarse flame
#

now the game don't crash, but do the same thing as before

devout nebula
#

It should beadjust speed one

#

Adjust speed 0

coarse flame
#

ok

devout nebula
#

Instead of pause

coarse flame
#

i think im doing wrong

pastel finchBOT
#

studio** You are now Level 2! **studio

coarse flame
#

in that part you say to turn in to Stop right?

#

if yes, still turning back to normal without the click

#

i need to sleep sorry, tomorrow im coming back

coarse flame
#

i think the problem is here

task.delay(poseTrack.Length - poseTrack.TimePosition, function()
#
task.delay(poseTrack.Length - poseTrack.TimePosition, function()
                if poseTrack.IsPlaying and isPosing then
                    poseTrack:Stop()
                end
            end)
#

someone helpcrying

#

i did something!!!!!

#

now when i click the animation goes normaly, but if i click during the animation it freeze at the time i had clicked (i think i wrote it right... im not good in english)