I am trying to make a script that when you hover over a button it does a cool animation. Where im stuck is that I’m trying to make it that no matter how many buttons I add to the GUI screen I won’t need to configure my script and manually wire them to work for each one I add.
So this has a similar function:
Everytime a player is added, it automatically wires it so that it can detect if that player’s character was added or removed.
I go through a folder that has object values to buttons, and make a :Connect function for each (Entering/Leaving)
This for some reason doesn’t work. It doesn’t output an error either. Anybody have a solution? Please help me…
local button = <button location>
button.MouseEnter:Connect(function()
<show the animation>
end)
button.MouseLeave:Connect(function()
<stop the animation>
end)
– If my calculations are correct then this Script should work
local Rep = game:GetService("ReplicatedStorage")
local Buttons = script.Parent -- place this script inside buttons. If my calculations are correct your buttons should be in the Buttons Folder
for i, item in pairs(Buttons:GetDescendants()) do
if item:isA("ObjectValue") then
local check = Buttons:WaitForChild(tostring(item.Value))
if check then
if check:isA("GuiButton") then
check.MouseEnter:Connect(function()
print("Enter")
end)
check.MouseLeave:Connect(function()
print("Leave")
end)
end
end
end
end
It looks like the issue is that you are looping through the Buttons folder and not getting the contents inside of the TitleScreen.
Essentially what your script is doing is checking if the folder “TitleScreen” is an objectValue, which of course, it isn’t. maybe try getting the contents with something like item:GetChildren()[1].
im dumb, you used getdescendants, I’ll think of something soon
– If my calculations are correct then this Script should work
– Place the Script in the buttons folder.
local Rep = game:GetService("ReplicatedStorage")
local Buttons = script.Parent -- place this script inside buttons folder.
for i, item in pairs(Buttons:GetDescendants()) do
if item:isA("ObjectValue") then
for i, button in pairs(Buttons:GetDescendants()) do
if string.lower(button.Name) == string.lower(tostring(item.Value)) then -- item.Value should be the button name
if button:isA("GuiButton") then
button.MouseEnter:Connect(function()
print("Enter")
end)
button.MouseLeave:Connect(function()
print("Leave")
end)
end
end
end
end
end
You could probably make it fire a remote event for client instead of print. and then you can add a local script that checks if it is fired and print(“whatever you want”) if true
That wouldn’t make sense though, if it doesn’t print then it wont fire a remote event either. I think its the problem of how I played out the coding, for example this image:
Is using :Connect() from the beggining
while im using a for loop