0

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

Edited 9 months 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 671
9 months ago
Edited 9 months 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 48 — 9mo
0
0
FirezDevv 147
9 months ago

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)

0
im sorry but i found the solution. Thanks For Trying to help! :] HKprogram 48 — 8mo
0
Ik both work but my version allows you to put as many spawns without updating the script FirezDevv 147 — 8mo
-1
DemGame 246
9 months ago
Edited 9 months 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 671 — 9mo
0
I am happy that you tried to help But I found the answer by @Pupppy44 . HKprogram 48 — 9mo