Still have questions? Join our Discord server and get real time help.
0

# is there any way to randomise Teleport To A Random Part in a folder?

Edited 7 days ago

So i am Working on a startup Gui that When you click A play button (Gui) You will teleport to a random Part.

the thing is that i Can tp to the block but I dont know how To Teleport To a random block

heres the code:

Gui.MouseButton1Click:Connect(function()
game.Players.LocalPlayer.character.Torso.CFrame = CFrame.new(workspace.Game.TeleportRandom.Teleport1.Position) -- teleport
end


I have looked for help in Google But No Resluts for what i am looking for.

Do someone know How I can fix this?

0
Pupppy44 458
7 days ago
Edited 7 days ago

You could try

Gui.MouseButton1Click:Connect(function()
local Number = math.random(1,10)
game.Players.LocalPlayer.Character.HumanoidRootPart.CFrame = CFrame.new(workspace.Game.TeleportRandom[tostring(Number)].Position)
end)


Notes: Make sure there's parts in the folder that are named 1-10.

0
Works Well! Thank you HKprogram 2 — 7d
0
0

here is another way I am sure it works

Gui.MouseButton1Click:Connect(function()
local chosen = workspace.Game.TeleportRandom:GetChildren()[math.random(1,#workspace.Game.TeleportRandom:GetChildren())]
game.Players.LocalPlayer.character.Torso.Position = chosen.CFrame
end)

-1
DemGame 107
7 days ago
Edited 7 days ago

I'm pretty new at scripting, so I do not think that my solution is the most efficient way to do this, but here is what I got:

local teleportchooser = math.random(0,10)
--choose what teleporter to teleport to by choosing a random number between 0 and 10

Gui.MouseButton1Click:Connect(function()
game.Players.LocalPlayer.character.Torso.CFrame = CFrame.new(game.workspace.Folder:FindFirstChild(teleportchooser)) -- teleport
end



Make sure that there is a folder in workspace with parts named 1, 2, 3, 4, 5, 6, 7, 8, 9, and 10.

0
this wont work Pupppy44 458 — 7d
0
I am happy that you tried to help But I found the answer by @Pupppy44 . HKprogram 2 — 7d