Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How can I make players teleport to a part?

Alright, so I have tried asking this before probably a year ago. I cannot figure out why this script does not work. I've tried working around it so many ways so far and I can't seem to find out what is wrong (even after taking a while away from this and then rewriting the script).

I am trying to teleport the players 3 seconds after the map spawns in:

-- Inside the PlayerAdded function
if chosen.Value ~= "" then
	mapSelected = true
	spawnMap()
	wait(3)
	movePlayers()
	return
end

But here are the two functions, spawnMap() and movePlayers() :

function spawnMap()
	local mapName = workspace.CurrentMap:WaitForChild("ChosenMap") -- A StringValue
	local map = game.ReplicatedStorage.Maps:FindFirstChild(mapName.Value)
	if map.Name == mapName.Value and mapSelected then
		wait()
		local newmap = map:Clone()
		newmap.Parent = workspace
		spawnpoint.Parent = workspace
		spawnpoint.Position = workspace.Spawn.Position -- Temporary position for testing
	end
end

function movePlayers()
	for i,v in pairs(players) do
    	v.Character.HumanoidRootPart.CFrame = spawnpoint * CFrame.new(math.random(5,10),0,math.random(5,10))
	end

I am seeing no errors as of now, but players do not teleport. I've also tried:

v.Character:FindFirstChild("HumanoidRootPart").CFrame = spawnpoint * CFrame.new(math.random(5,10),0,math.random(5,10))

2 answers

I think this is it

humanoid:MoveTo(part.Position)

Did this help

1 comment

0

MoveTo is the function to make a player walk if I'm not mistaken.

A teleportation script is simply like this:

script.Parent.Touched:connect(function(hit) 
 if hit.Parent:FindFirstChild('Humanoid') then 
  hit.Parent.Head.CFrame = CFrame.new(COORDINATION HERE)
 end
end)

--coordination here put the position

This might teleport people while people touched the script's parent.

If you need answer, ask below comment. I'll get to sleep so uh, cya later.

3 comments

0

The player doesn't touch a part, the game just teleports the players to a spawn in the map.

0

I know, just combine the script with your script, maybe it's works! I think that delete the line 1 and line 5, the middle thing was just a code that teleports peoples.

0

Doesn't work, thanks for trying though.

This discussion is preserved as it was. New answers, comments, and votes are closed.