Been wondering how can I use tables, since this will be so useful for me and much more simpler way to handle and organize my codes. Pardon me, I’m still new to using tables
local button = {
[1] = script.Parent:WaitForChild("1Pic"):WaitForChild("Image"),
[2] = script.Parent:WaitForChild("2Pic"):WaitForChild("Image"),
[3] = script.Parent:WaitForChild("3Pic"):WaitForChild("Image")
}
-- // same goes for this part too, I don't know how to use tables to reference
-- // all of the buttons for the tween: ...(button[1], ...)
local TweenOut = TweenService:Create(button[1], IconTween, GoalOut)
local TweenIn = TweenService:Create(button[1], IconTween, GoalIn)
-- // I want to use the Table I made to reference all of the buttons in this
-- // code so whenever my Mouse hovers at any at the Table, it'll just play the Tween
button[1].MouseEnter:Connect(function()
TweenIn:Play()
end)
button[1].MouseLeave:Connect(function()
TweenOut:Play()
end)
Using tables for that isnt really optimized, you should just store them all in a frame and just assign a variable to the frame. then you can get the buttons from it.
Make a pairs loop from the scrolling frame and check if its a frame. Then connect the tween functions if it is a frame.
Basically:
for _, v in pairs(script.Parent:GetChildren()) do
if v:isA("Frame") then
v.MouseEnter:Connect(function()
tweenIn(v)
end)
v.MouseLeave:Connect(function()
tweenOut(v)
end)
end
end
They should become functions with the frame as the first parameter. Inside the function, you should tween the frame in the parameter.
remember to play it btw
local TweenOut = TweenService:Create(IconTween, GoalOut)
local TweenIn = TweenService:Create(IconTween, GoalIn)
for _, v in pairs(script.Parent.Parent:GetChildren()) do
if v:isA("Frame") then
v.MouseEnter:Connect(function() -- Should I put the TweenInfo here?
TweenIn(v) -- and what is this purpose?
-- should I put the tween:play here inside too?
end)
v.MouseLeave:Connect(function()
TweenOut(v)
end)
end
end
local function TweenIn(function(frame)
TweenService:Create(frame,TweenInfo.new(.1),GoalIn):Play(
end)
local function TweenOut(function(frame)
TweenService:Create(frame,TweenInfo.new(.1),GoalOut):Play(
end)
OHHH my god- I didn’t realize that. I’m getting the hang of it now.
So basically:
for _, v in pairs(script.Parent.Parent:GetChildren()) do
if v:isA("Frame") then -- // This Detects if the Chilren are a Frame, correct?
v.MouseEnter:Connect(function()
TweenIn(v) -- this is the function, and the first parameter is sent
-- to the function TweenIn.
end)
...
local function TweenIn(function(frame)
TweenService:Create(frame, IconTween,GoalIn):Play()
end)
local function TweenOut(function(frame)
TweenService:Create(frame, IconTween,GoalOut):Play()
end)
for _, v in pairs(script.Parent.Parent:GetChildren()) do
if v:isA("Frame") then
v.MouseEnter:Connect(function()
TweenIn(v)
end)
v.MouseLeave:Connect(function()
TweenOut(v)
end)
end
end
some errors in the coding
This broke me sorry Tables are confusing me so bad @keremMCT
I’m not sure if you know this but, assigning a table key to an instance doesn’t actually create a copy of all the data. It only provides a reference. Using tables is fine.
local function TweenIn(frame)
TweenService:Create(frame, IconTween,GoalIn):Play()
end
local function TweenOut(frame)
TweenService:Create(frame, IconTween,GoalOut):Play()
end
for _, v in pairs(script.Parent.Parent:GetChildren()) do
if v:isA("Frame") then
v.MouseEnter:Connect(function()
TweenIn(v)
end)
v.MouseLeave:Connect(function()
TweenOut(v)
end)
end
end
i don’t see the use in having two seperate tween functions especially since you aren’t waiting for the tweens
local TS = game:GetService("TweenService")
local tInfo = TweenInfo.new()
local Games = script.Parent:GetChildren() -- Assuming these buttons will teleport you to games
for _, GameFrame in Games do -- ipairs() would work too
if not GameFrame:IsA("Frame") then continue end
local GameButton = GameFrame.Button -- I'd suggest renaming 'Image' to 'Button'
GameButton.MouseEnter:Connect(function()
TS:Create(GameButton, tInfo, InGoal):Play()
end)
GameButton.MouseLeave:Connect(function()
TS:Create(GameButton, tInfo, OutGoal):Play()
end)
end