Hello, I have two viewport frames and I want to make a script that I can move around them and select them with these:
Looks squished because I took it in Studio.
I made my script but it gives an error, I couldn’t really find why it happens. Also I need to figure out a soluion for how can I hide them when they got out of the Gui frame in the middle so I hope you can help with it too.
- My script:
--Definitions
local OutFrame = script.Parent
local LeftArrow = OutFrame:WaitForChild("LeftArrow")
local RightArrow = OutFrame:WaitForChild("RightArrow")
local VPFrameFolder = OutFrame:WaitForChild("ViewportFrames")
local allVPs = VPFrameFolder:GetChildren()
local tweenService = game:GetService("TweenService")
local inFramePos = UDim2.new{0.5,0,0.647,0}
local outFramePosLeft = UDim2.new(0, 0,0.363, 0)
local outFramePosRight = UDim2.new(0.639,0,0.363,0)
--Indexes
local index = 0
local indexMin = 0
local indexMax = 1
--IndexRename
for i, value in pairs(allVPs) do
value.Name = (tostring(i) .. " " .. value.Name)
end
--Tweens
local function leftSwipe(frame)
local tweenInfo = TweenInfo.new(1,Enum.EasingStyle.Linear, Enum.EasingDirection.In, 0, false)
local tween = tweenService:Create(frame, tweenInfo, {Position = outFramePosLeft})
tween:Play()
wait(1)
end
local function rightSwipe(frame)
local tweenInfo = TweenInfo.new(1,Enum.EasingStyle.Linear, Enum.EasingDirection.In, 0, false)
local tween = tweenService:Create(frame, tweenInfo, {Position = outFramePosRight})
tween:Play()
end
local function toCenterSwipe(frame)
local tweenInfo = TweenInfo.new(1,Enum.EasingStyle.Linear, Enum.EasingDirection.In, 0, false)
local tween = tweenService:Create(frame, tweenInfo, {Position = outFramePosRight})
tween:Play()
end
--Functions
local function indexCal(buttonname)
if type(buttonname) ~= 'string' then
assert(false, "Put a string here.")
elseif buttonname == "Right" then
index = index+1
if index > indexMax then
index = indexMin
end
elseif buttonname == "Left" then
index = index - 1
if index < indexMin then
index = indexMax
end
end
end
local function lookForGui(index)
for _, v in pairs(allVPs)do
local stringName = v.Name
local stringNameAll = string.split(stringName, " ")
for _, v in pairs (stringNameAll) do
if v == index then
return v
end
end
end
end
local function calculatePreviousLeft(index)
if index-1 >= indexMin then return index-1 else return indexMin end
end
local function calculatePreviousRight(index)
if index+1 <= indexMax then return index+1 else return indexMax end
end
local function onRightButtonClick()
indexCal("Right")
local NextGui = lookForGui(index)
local previousGui = lookForGui(calculatePreviousRight(index))
rightSwipe(previousGui)
toCenterSwipe(NextGui)
end
local function onLeftButtonClick()
indexCal("Left")
local NextGui = lookForGui(index)
local previousGui = lookForGui(calculatePreviousLeft(index))
leftSwipe(previousGui)
toCenterSwipe(NextGui)
end
--Events
RightArrow.MouseButton1Click:Connect(onRightButtonClick())
LeftArrow.MouseButton1Click:Connect(onLeftButtonClick())
Error: