Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local Players = game:GetService("Players")
- local AssetService = game:GetService("AssetService")
- local TeleportService = game:GetService("TeleportService")
- local player = Players.LocalPlayer
- local playerGui = player:WaitForChild("PlayerGui")
- -- Create ScreenGui
- local screenGui = Instance.new("ScreenGui")
- screenGui.Name = "SubPlacesGui"
- screenGui.Parent = playerGui
- -- Create main frame
- local mainFrame = Instance.new("Frame")
- mainFrame.Size = UDim2.new(0, 400, 0, 300)
- mainFrame.Position = UDim2.new(0.5, -200, 0.5, -150)
- mainFrame.BackgroundColor3 = Color3.fromRGB(30, 30, 30)
- mainFrame.BorderSizePixel = 0
- mainFrame.Parent = screenGui
- -- Title label
- local titleLabel = Instance.new("TextLabel")
- titleLabel.Size = UDim2.new(1, 0, 0, 30)
- titleLabel.BackgroundColor3 = Color3.fromRGB(45, 45, 45)
- titleLabel.TextColor3 = Color3.new(1, 1, 1)
- titleLabel.Font = Enum.Font.SourceSansBold
- titleLabel.TextSize = 20
- titleLabel.Text = "Sub-Places"
- titleLabel.Parent = mainFrame
- -- Show Sub-Places Button
- local showButton = Instance.new("TextButton")
- showButton.Size = UDim2.new(0, 150, 0, 40)
- showButton.Position = UDim2.new(0.5, -75, 0, 40)
- showButton.BackgroundColor3 = Color3.fromRGB(70, 130, 180)
- showButton.TextColor3 = Color3.new(1, 1, 1)
- showButton.Font = Enum.Font.SourceSansBold
- showButton.TextSize = 18
- showButton.Text = "Show Sub-Places"
- showButton.Parent = mainFrame
- -- Scrolling frame to hold place buttons
- local scrollingFrame = Instance.new("ScrollingFrame")
- scrollingFrame.Size = UDim2.new(1, -20, 1, -100)
- scrollingFrame.Position = UDim2.new(0, 10, 0, 90)
- scrollingFrame.BackgroundColor3 = Color3.fromRGB(40, 40, 40)
- scrollingFrame.BorderSizePixel = 0
- scrollingFrame.CanvasSize = UDim2.new(0, 0, 0, 0)
- scrollingFrame.ScrollBarThickness = 8
- scrollingFrame.Parent = mainFrame
- -- UIListLayout for scrolling frame
- local listLayout = Instance.new("UIListLayout")
- listLayout.Padding = UDim.new(0, 5)
- listLayout.SortOrder = Enum.SortOrder.LayoutOrder
- listLayout.Parent = scrollingFrame
- -- Function to clear previous entries
- local function clearSubPlaceEntries()
- for _, child in pairs(scrollingFrame:GetChildren()) do
- if child:IsA("Frame") then
- child:Destroy()
- end
- end
- end
- -- Function to create a sub-place entry with place name and place ID
- local function createSubPlaceEntry(place)
- local entryFrame = Instance.new("Frame")
- entryFrame.Size = UDim2.new(1, 0, 0, 50) -- Increased height to fit two labels
- entryFrame.BackgroundColor3 = Color3.fromRGB(60, 60, 60)
- entryFrame.Parent = scrollingFrame
- local placeNameLabel = Instance.new("TextLabel")
- placeNameLabel.Size = UDim2.new(0.6, 0, 0.5, 0)
- placeNameLabel.BackgroundTransparency = 1
- placeNameLabel.TextColor3 = Color3.new(1, 1, 1)
- placeNameLabel.Font = Enum.Font.SourceSansBold
- placeNameLabel.TextSize = 18
- placeNameLabel.Text = "Name: " .. tostring(place.Name or "Unknown")
- placeNameLabel.TextXAlignment = Enum.TextXAlignment.Left
- placeNameLabel.Parent = entryFrame
- local placeIdLabel = Instance.new("TextLabel")
- placeIdLabel.Size = UDim2.new(0.6, 0, 0.5, 0)
- placeIdLabel.Position = UDim2.new(0, 0, 0.5, 0)
- placeIdLabel.BackgroundTransparency = 1
- placeIdLabel.TextColor3 = Color3.new(1, 1, 1)
- placeIdLabel.Font = Enum.Font.SourceSans
- placeIdLabel.TextSize = 16
- placeIdLabel.Text = "PlaceId: " .. tostring(place.PlaceId)
- placeIdLabel.TextXAlignment = Enum.TextXAlignment.Left
- placeIdLabel.Parent = entryFrame
- local joinButton = Instance.new("TextButton")
- joinButton.Size = UDim2.new(0.35, 0, 0.8, 0)
- joinButton.Position = UDim2.new(0.65, 0, 0.1, 0)
- joinButton.BackgroundColor3 = Color3.fromRGB(100, 170, 100)
- joinButton.TextColor3 = Color3.new(1, 1, 1)
- joinButton.Font = Enum.Font.SourceSansBold
- joinButton.TextSize = 18
- joinButton.Text = "Join"
- joinButton.Parent = entryFrame
- joinButton.MouseButton1Click:Connect(function()
- -- Teleport player to the selected place
- TeleportService:Teleport(place.PlaceId, player)
- end)
- end
- -- On clicking Show Sub-Places button
- showButton.MouseButton1Click:Connect(function()
- showButton.Text = "Loading..."
- showButton.Active = false
- showButton.AutoButtonColor = false
- clearSubPlaceEntries()
- local success, pagesOrError = pcall(function()
- return AssetService:GetGamePlacesAsync()
- end)
- if success then
- local pages = pagesOrError
- local allPlaces = {}
- -- Iterate through all pages to collect all places
- repeat
- for _, place in ipairs(pages:GetCurrentPage()) do
- table.insert(allPlaces, place)
- end
- if not pages.IsFinished then
- pages:AdvanceToNextPageAsync()
- end
- until pages.IsFinished
- if #allPlaces == 0 then
- local noPlacesLabel = Instance.new("TextLabel")
- noPlacesLabel.Size = UDim2.new(1, 0, 0, 40)
- noPlacesLabel.BackgroundTransparency = 1
- noPlacesLabel.TextColor3 = Color3.new(1, 1, 1)
- noPlacesLabel.Font = Enum.Font.SourceSansItalic
- noPlacesLabel.TextSize = 18
- noPlacesLabel.Text = "No sub-places found."
- noPlacesLabel.Parent = scrollingFrame
- else
- for _, place in ipairs(allPlaces) do
- createSubPlaceEntry(place)
- end
- end
- -- Adjust canvas size based on content
- scrollingFrame.CanvasSize = UDim2.new(0, 0, 0, listLayout.AbsoluteContentSize.Y)
- else
- -- Error fetching places
- local errorLabel = Instance.new("TextLabel")
- errorLabel.Size = UDim2.new(1, 0, 0, 40)
- errorLabel.BackgroundTransparency = 1
- errorLabel.TextColor3 = Color3.new(1, 0, 0)
- errorLabel.Font = Enum.Font.SourceSansBold
- errorLabel.TextSize = 18
- errorLabel.Text = "Error fetching sub-places."
- errorLabel.Parent = scrollingFrame
- end
- showButton.Text = "Show Sub-Places"
- showButton.Active = true
- showButton.AutoButtonColor = true
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement