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
if Humanoid.Parent:FindFirstChild("Torso") then
Torso.CFrame = CFrame.new(ChosenSpawnPoint.Position + Vector3.new(0,3,0))
elseif Humanoid.Parent:FindFirstChild("UpperTorso") then
UpperTorso.CFrame = CFrame.new(ChosenSpawnPoint.Position + Vector3.new(0,3,0))
end
wait(1)
script.Parent.Parent.Parent:Destroy()
end)
If you can help me, I'd be grateful :)
