How can I make it when I press a gui button I randomly get teleported to any part in a folder

So basically I made a folder in the workspace that has multiple parts with the same name “part” and I want when a player clicks a GUI button they get teleported to a random part in the folder

1 Like

Read Activated and after you understand how that event works, you can use math.random to “randomly” choose a number.

Index into the folder using that number and teleport your player to there.

local button = script.Parent
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local hrp = character:WaitForChild("HumanoidRootPart")
local folder = workspace:WaitForChild("Folder")
local parts = folder:GetChildren()

button.MouseButton1Click:Connect(function()
	local randomPart = parts[math.random(1, #parts)]
	hrp.CFrame = randomPart.CFrame
end)

Local script inside the button itself.

1 Like

Thank you so much it really helps