Here’s the piece of the code that give out the errors.
-- << Functions >> --
local function MouseEnter(ImageLabel)
SoundFX.Mouse_Hover:Play()
local tween = TweenService:Create(ImageLabel, TweenInfos.MouseEnter, Tweens.MouseEnter)
end
local function MouseLeave(ImageLabel)
local tween = TweenService:Create(ImageLabel, TweenInfos.MouseLeave, Tweens.MouseLeave)
end
-- << Connections >> --
for i, Button in pairs(UIElements._Buttons:GetChildren()) do
if Button:IsA("ImageLabel") then
local bttn = Button.TextButton
bttn.MouseEnter:Connect(MouseEnter(Button))
bttn.MouseLeave:Connect(MouseLeave(Button))
bttn.MouseButton1Down:Connect(MouseButtonDown)
bttn.MouseButton1Up:Connect(MouseButtonUp)
end
end
If someone could help me I’d be very grateful thank you!
It must be written like the two bottom connections. No parentheses, no parameters.
Not to mention the fact that MouseEnter and MouseLeave run for the specific GuiObject it’s connected to, so there’s no reason to even pass the ImageLabel through the function.
You must write it as bttn.MouseEnter(MouseEnter) and bttn.MouseLeave(MouseLeave)
Though, the function is relying on a parameter, but connecting functions like that don’t allow you to pass parameters.
I would instead write the code like this:
for i, Button in pairs(UIElements._Buttons:GetChildren()) do
if Button:IsA("ImageLabel") then
local bttn = Button.TextButton
bttn.MouseEnter:Connect(MouseEnter(function()
SoundFX.Mouse_Hover:Play()
local tween = TweenService:Create(Button, TweenInfos.MouseEnter, Tweens.MouseEnter):Play()
end)
bttn.MouseLeave:Connect(function())
local tween = TweenService:Create(Button, TweenInfos.MouseLeave, Tweens.MouseLeave):Play()
end)
bttn.MouseButton1Down:Connect(MouseButtonDown)
bttn.MouseButton1Up:Connect(MouseButtonUp)
end
end
And sorry for poor formatting. I’m writing this all on my phone.
You need to connect to a function, I would recommend doing this by having MouseEnter/MouseLeave return a function like so
-- << Functions >> --
local function MouseEnter(ImageLabel)
return function()
SoundFX.Mouse_Hover:Play()
local tween = TweenService:Create(ImageLabel, TweenInfos.MouseEnter, Tweens.MouseEnter)
end
end
local function MouseLeave(ImageLabel)
return function()
local tween = TweenService:Create(ImageLabel, TweenInfos.MouseLeave, Tweens.MouseLeave)
end
end
When you type MouseEnter(Button) it calls the function so it is evaluated then and there, with this modification calling the function returns another function that will be connected to your event properly.