-- Place this script inside StarterCharacterScripts
-- Replace with your AnimationId
local animationId = "rbxassetid://15571446961"
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
-- Wait for the character to fully load
character:WaitForChild("Humanoid")
-- Create an Animation instance
local animation = Instance.new("Animation")
animation.AnimationId = animationId
-- Create an AnimationTrack instance
local animationTrack = character.Humanoid:LoadAnimation(animation)
-- Variable to track if the animation is playing
local isDancing = false
-- Function to start the dance animation
local function startDancing()
if not isDancing then
isDancing = true
animationTrack:Play()
end
end
-- Function to stop the dance animation
local function stopDancing()
if isDancing then
isDancing = false
animationTrack:Stop()
end
end
-- Connect the functions to the character's Humanoid movement and state
local humanoid = character:WaitForChild("Humanoid")
-- Monitor the Humanoid's movement state and actions
humanoid.Running:Connect(function(speed)
if speed > 0 then
stopDancing()
end
end)
-- Monitor changes in the Humanoid's state
humanoid.StateChanged:Connect(function(_, newState)
if newState == Enum.HumanoidStateType.Seated or
newState == Enum.HumanoidStateType.Jumping or
newState == Enum.HumanoidStateType.Freefall then
stopDancing()
elseif newState == Enum.HumanoidStateType.GettingUp or
newState == Enum.HumanoidStateType.Physics then
startDancing()
end
end)
-- Start dancing when the player character spawns
startDancing()
To embed this project on your website, copy the following code and paste it into your website's HTML: