How would I make it so if you click a button (TextButton) then a dance animation plays? There are a few tutorials on youtube but none of them are that good and I also want it FE so everyone can see the dance.
for _, dances in pairs(script.Parent.Pages:GetChildren()) do
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local anim
local playing = false
-- We will pause the script to wait for the chracter to load
repeat wait()
until Player.Character
local char = Player.Character
local Humanoid = char:WaitForChild("Humanoid")
-- Creat a Animtion In The Player
local danceAnimation = Instance.new("Animation")
danceAnimation.Parent = char
danceAnimation.Name = "The Robot"
-- Setup the animtion to play
local function setupAnimation (id)
if playing then return end
playing = true
local selectedId = "rbxassetid://"..id
danceAnimation.AnimationId = selectedId
anim = Humanoid:LoadAnimation(danceAnimation)
anim:Play()
end
-- Stops the current animation playing
script.Parent.Stop.MouseButton1Click:Connect(function()
if anim then
anim:Stop()
playing = false
end
end)
-- detects when a button is pressed
for _,v in pairs(dances:GetChildren()) do
if v:IsA("TextButton") then
v.MouseButton1Click:Connect(function()
setupAnimation(v.Name)
end)
end
end
end
Put this inside your screenGUI. You’ll need to then locate your frame, and the textbuttons within it (these buttons will be the buttons that on press, create an animation. Find your animation you want to use in the roblox library, copy the ID (Set of numbers), and paste that as the NAME of your textbutton.
1 Like