FIXED] Help with checking animation handler

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

Here is the main code.
image
Here is the explorer
https://gyazo.com/342013e46413d0f8cab5f7f06721ea43
Here is a clip of the cloned buttons not working and the template working

Where is the script you are showing located in the explorer?

StarterGUI, inside the scrolling frame, I guess I forgot to snip that

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

So where should I put this in the code?

that would go in the same script, i would put it right below where you declared Remotes
and in the for loop say:

for _, button in pairs(ScrollingFrame:WaitForChild("Buttons"):GetChildren()) do
--rest of code here
end

I dont know the exact path to ScrollingFrame cuz i cant see everything in that Explorer pic

Okay, Ill test it out right now and let you know if it works

Like this?

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

Why use a module for this, just use the normal methods for mouse enter and mouse leave, also why are you using :TweenSize.

My b, i realized that I think what Im telling you actually doesnt really matter in this case and something else is preventing it from working

I use a module because one click will make all the others come closer to each other

I figured it out, I needed to add a script to reset the script upon player added. Ill give you the solution since you tried to help

well thank you I appreciate that, good job on getting it working

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.