I am making a dance GUI for my game with 2 seperate pages. The code only works for one page, in this case page 1. How can I make the dance script function for both pages at the same time? This is my best effort below, and it did not work, still only triggering page 1.
local dances = script.Parent.Pages.Page1 or
script.Parent.Pages.Page2
for _, dances in pairs(script.Parent.Pages:GetChildren()) do
-- Code here
end
This allows you to add a bunch of pages without needing to touch the code, and if you have v form the loop be dances, you don’t need to edit your original dance GUI code.
This is what it currently looks like with my whole script. The first page dances work but the second page is still unresponsive.
for _, dances in pairs(script.Parent.Pages:GetChildren()) do
local dances = script.Parent.Pages.Page1 or
script.Parent.Pages.Page2
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