Basically, I have made a script that automatically adds a new TextButton to a Frame depending on what is inside a Folder. Upon clicking the button it teleports you to that location. (hard to explain so hopefully these screenshots help)
GUI:
Folder:
E.g. clicking the “Home” button would teleport you to the “Home” part.
Code:
-- Client
for i,v in pairs(game.Workspace.LocationMarkers:GetChildren()) do
local NewButton = script.Template:Clone()
NewButton.Parent = script.Parent.Frame
NewButton.Text = v.Name
NewButton.Name = v.Name
end
for i,Button in pairs(script.Parent.Frame:GetChildren()) do
if Button:IsA("TextButton") then
Button.MouseButton1Click:Connect(function()
for i,Part in pairs(game.Workspace.LocationMarkers:GetChildren()) do
if Button.Name == Part.Name then
game.ReplicatedStorage.TeleportSystem.TeleportPlayer:FireServer(Part.Position)
end
end
end)
end
end
-- Server
game.ReplicatedStorage.TeleportSystem.TeleportPlayer.OnServerEvent:Connect(function(player, location)
player.Character.HumanoidRootPart.Position = location
end)
Adding on to @D0RYU, setting the parent property before setting the properties will make the script constantly look for the part and check if it still exists to set the properties but if you set the parent property after setting the properties, the script will already have the properties set and it’ll not have made the part yet so it doesn’t have to check for the part.
script.Parent.MouseButton1Click:Connect(function()
local home = workspace.LocationMarkers.Home
local char = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait()
local root = char:WaitForChild("HumanoidRootPart")
root.CFrame = home.CFrame
end)
(Note: please put this in a local script inside the button)