#could i get help with this animation script

3 messages · Page 1 of 1 (latest)

bright ravine
#
-- Define the animation ID and audio ID
local animationId = "INSERT_ANIMATION_ID_HERE" -- Replace with the ID of your animation
local audioId = "INSERT_AUDIO_ID_HERE" -- Replace with the ID of your audio

-- Function to play the animation and audio
local function playAnimation()
    -- Load the animation
    local animation = Instance.new("Animation")
    animation.AnimationId = "rbxassetid://" .. animationId

    -- Play the animation on the player's character
    local humanoid = game.Players.LocalPlayer.Character:WaitForChild("Humanoid")
    local animationTrack = humanoid:LoadAnimation(animation)
    animationTrack:Play()

    -- Create and play the audio
    local sound = Instance.new("Sound")
    sound.SoundId = "rbxassetid://" .. audioId
    sound.Parent = game.Players.LocalPlayer.Character.HumanoidRootPart
    sound:Play()

    -- Move the camera during the animation
    local camera = game.Workspace.CurrentCamera
    local originalCameraCFrame = camera.CFrame

    -- Example camera movement
    for i = 1, 100 do
        local t = i / 100
        local newCameraCFrame = originalCameraCFrame * CFrame.new(0, 0, t)
        camera.CFrame = newCameraCFrame
        wait(0.1)
    end

    -- Reset the camera position after the animation
    camera.CFrame = originalCameraCFrame

    -- Listen forthe "/endAnimation" command
    game.Players.LocalPlayer.Chatted:Connect(function(message)
        if message:lower() == "/endanimation" then
            -- Stop the animation and audio
            animationTrack:Stop()
            sound:Stop()
        end
    end)

    -- Listen for animation completion
    animationTrack.Stopped:Connect(function()
        -- Stop the audio when the animation ends
        sound:Stop()
    end)
end

-- Example command to play the animation
game.Players.LocalPlayer.Chatted:Connect(function(message)
    if message:lower() == "/playanimation" then
        playAnimation()
    end
end)