Hello! I have a Button animation script that applies an animation to the button. In my game, I am cloning a button into the folder that applies the animation. When I load into the game, the cloned buttons don’t work but the template does. Is their a way to repeat the application of the script.
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Remotes = ReplicatedStorage:WaitForChild("Remotes")
local MouseHover = require(script:WaitForChild("MouseHover"))
for _, button in pairs(script.Parent:WaitForChild("Buttons"):GetChildren()) do
local buttonDebounce = false
if button:IsA("ImageButton") then
local default = button.Size
local enlarge = UDim2.new(button.Size.X.Scale * 1.04, 0, button.Size.Y.Scale * 1.04)
local shrink = UDim2.new(button.Size.X.Scale * .95, 0, button.Size.Y.Scale * .95)
local MouseEnter, MouseLeave = MouseHover.MouseEnterLeaveEvent(button)
MouseEnter:Connect(function()
button:TweenSize(enlarge, Enum.EasingDirection.Out, Enum.EasingStyle.Quad, .1, true)
end)
MouseLeave:Connect(function()
button:TweenSize(default, Enum.EasingDirection.Out, Enum.EasingStyle.Quad, .1, true)
end)
button.MouseButton1Up:Connect(function()
if buttonDebounce == false then
buttonDebounce = true
spawn(function()
button:TweenSize(shrink, Enum.EasingDirection.Out, Enum.EasingStyle.Quad, .1, true)
wait(.1)
button:TweenSize(default, Enum.EasingDirection.Out, Enum.EasingStyle.Quad, .05, true)
end)
wait(0)
buttonDebounce = false
end
end)
end
end
ok i think i know the issue then, so the script is only applying to the buttons in the StarterGui which players cannot interact with. StarterGui replicates to a player’s PlayerGui whenever a player joins the game, and players CAN interact with PlayerGui so when accessing the children of the button folder, you need to access it through PlayerGui
something along the lines of this:
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local gui = Player:WaitForChild("PlayerGui")
once you have the PlayerGui, just get the path to your buttons folder then loop through those buttons like you did above in the original script and I believe you should be good
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Remotes = ReplicatedStorage:WaitForChild("Remotes")
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local gui = Player:WaitForChild("PlayerGui")
local ScrollingFrame = script.Parent
local MouseHover = require(script:WaitForChild("MouseHover"))
for _, button in pairs(ScrollingFrame:WaitForChild("Buttons"):GetChildren()) do
local buttonDebounce = false
if button:IsA("ImageButton") then
local default = button.Size
local enlarge = UDim2.new(button.Size.X.Scale * 1.04, 0, button.Size.Y.Scale * 1.04)
local shrink = UDim2.new(button.Size.X.Scale * .95, 0, button.Size.Y.Scale * .95)
local MouseEnter, MouseLeave = MouseHover.MouseEnterLeaveEvent(button)
MouseEnter:Connect(function()
button:TweenSize(enlarge, Enum.EasingDirection.Out, Enum.EasingStyle.Quad, .1, true)
end)
MouseLeave:Connect(function()
button:TweenSize(default, Enum.EasingDirection.Out, Enum.EasingStyle.Quad, .1, true)
end)
button.MouseButton1Up:Connect(function()
if buttonDebounce == false then
buttonDebounce = true
spawn(function()
button:TweenSize(shrink, Enum.EasingDirection.Out, Enum.EasingStyle.Quad, .1, true)
wait(.1)
button:TweenSize(default, Enum.EasingDirection.Out, Enum.EasingStyle.Quad, .05, true)
end)
wait(0)
buttonDebounce = false
end
end)
end
end