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?
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.
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)
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.