Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 3 years ago
Edited 3 years 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?

3 answers

Log in to vote
0
Answered by
Pupppy44 671 Moderation Voter
3 years ago
Edited 3 years 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 — 3y
0
Please mark it as answered :) Pupppy44 671 — 3y
Ad
Log in to vote
0
Answered by
FirezDevv 162
3 years 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 — 3y
0
Ik both work but my version allows you to put as many spawns without updating the script FirezDevv 162 — 3y
Log in to vote
-1
Answered by
DemGame 271 Moderation Voter
3 years ago
Edited 3 years 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 — 3y
0
I am happy that you tried to help But I found the answer by @Pupppy44 . HKprogram 48 — 3y

Answer this question