Problem with teleporting player?

So i made a script where it teleports you to a random position when you spawn in but,
I have 3 problems, let me list it;

  1. How do i check if the player went to the correct position
  2. The script is not teleporting player?
  3. I noticed that my humanoid root part is not with my main body (head and more)

here is the full code:

local Pos1 = game.Workspace.Spectator.Spawn.SpawnLocation0
local Pos2 = game.Workspace.Spectator.Spawn.SpawnLocation1
local Pos3 = game.Workspace.Spectator.Spawn.SpawnLocation2

local Variables = {
	Pos1,
	Pos2,
	Pos3,
}

game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(char)
		local hum = char:WaitForChild("HumanoidRootPart")
		wait(2)
		local randomPosition = Variables[math.random(1,#Variables)]
		hum.CFrame = randomPosition.CFrame
		print(randomPosition.CFrame)
	end)
end)

Thanks!

Is your game R6?
If its R6 then use Torso instead of HumanoidRootPart

1 Like

Have you looked into this? CFrames | Roblox Creator Documentation

1 Like

Yes, I’m like 80% sure that it’s R6 ill try that!
Although, how would I check if the player went to the random position given?

You can use printing to tell the location teleported

2 Likes

R6 characters have a HumanoidRootPart & a Torso, R15 characters have a HumanoidRootPart but do not have a Torso, they have an UpperTorso & LowerTorso.

1 Like
local players = game:GetService("Players")
local spawns = game.Workspace.Spectator.Spawn
local Pos1 = spawns.SpawnLocation0
local Pos2 = spawns.SpawnLocation1
local Pos3 = spawns.SpawnLocation2

local Variables = {
	Pos1,
	Pos2,
	Pos3
}

players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(char)
		local hum = char:WaitForChild("HumanoidRootPart")
		task.wait(3)
		local randomPosition = Variables[math.random(1,#Variables)]
		hum.CFrame = randomPosition.CFrame
		print(randomPosition.CFrame)
	end)
end)

This should work, place in StarterPlayerScripts or StarterCharacterScripts.

1 Like