Teleporting a player to a random place in the map by a gui?
I need to(in my game) teleport a player to a random part in the map I've created. I'm using the table method of where you have the map, and then you have the "SpawnPoints" model inside said Map. From a GUI I've made I have a Text-Button, and there's a script inside said Text-Button which should teleport the player to a random spawnpoint in the "SpawnPoints" model"
--This is the script I'm using
local Workspace = game:GetService("Workspace")
local SpawnPoints = Workspace.Map.SpawnPoints:GetChildren()
local ChosenSpawnPoint = SpawnPoints[math.random(1,#SpawnPoints)]
script.Parent.MouseButton1Click:Connect(function(player)
local Humanoid = player.Humaoid
1 | if Humanoid.Parent:FindFirstChild( "Torso" ) then |
2 | Torso.CFrame = CFrame.new(ChosenSpawnPoint.Position + Vector 3. new( 0 , 3 , 0 )) |
4 | elseif Humanoid.Parent:FindFirstChild( "UpperTorso" ) then |
5 | UpperTorso.CFrame = CFrame.new(ChosenSpawnPoint.Position + Vector 3. new( 0 , 3 , 0 )) |
8 | script.Parent.Parent.Parent:Destroy() |
end)
If you can help me, I'd be grateful :)