Can't Make a working teleporting script that changes of destination constantly

Hello , So I wanted to make a script that I can change the destination whenever I want but I don’t know how to write it .

I have tried putting the Part name in a text so the script would grab the part name and then with the part name get the CFrame , I have tried putting it between [] and modifying the script alot but It still doesn’t work, Also I have tried finding a way to store part names etc but no sucess. Help is appreciated !

local tok = script.Parent.Parent.Backpack
function TelePlayers1()
	local location1 = tok.Destination.Text
	for i,v in pairs(game.Players:GetPlayers()) do
		if v.Character then
			if v.Character:findFirstChild("Torso") then
				v.Character.Torso.CFrame = CFrame.new(game.Workspace.TpList:FindFirstChild([location1].text).CFrame.p+Vector3.new(math.random(-0,0),0,math.random(-0,0)))

			end
		end
	end
end

You want to teleport the HumanoidRootPart for better results.

Ah , I didn’t know you could do this but I would need an exemple of how to use it because the script you see up is the only way I was able to make teleportation work.

Try putting all of your spawns (in this case, Parts) in one folder named SpawnPoints and then paste this code into a script:

local spawns = game.Players:FindFirstChild("SpawnPoints")
spawns = spawns:GetChildren()

for _, player in pairs() do
		local name = player.Name
		local body = workspace:FindFirstChild(name)
		local hrp = body:FindFirstChild("HumanoidRootPart")
		
		if hrp then
			local chosenSpawn = spawns[math.random(#spawns)]
			hrp.CFrame = chosenSpawn.CFrame
			table.remove(spawns, table.find(spawns, chosenSpawn))
end

This chooses a random spawn for a player and teleports them there.

Ah but the script I made up was for when you open a door etc , it teleports you to the destination stored in the script and then you get teleported to another room like a door , but not for spawn points sadly

Ah, yes, that was an accident, it teleports all players instead.

Yeah the Script I made is local so only you gets teleported

Maybe put this in an event?

local name = player.Name
local body = workspace:FindFirstChild(name)
local hrp = body:FindFirstChild("HumanoidRootPart")

if hrp then
local chosenSpawn = --your teleport point
hrp.CFrame = chosenSpawn.CFrame

I could try this but It doesn’t need to be in a event I think

Right, you can always use LocalPlayer.

I Have tried making it work but I need a way to make the script understand its the part name that Im giving it and not a text

Do you mean the destination?

local chosenSpawn = —teleport part goes here

Yeah it needs to grab the destination name

Yep, put that fragment of code with the other variables.

Its hard to explain but how do you make a object name storage ? like the text it can store text and the values can store numbers but I can’t seem to find a way to store letters correctly

Insert a StringValue for that.

1 Like

I was able to make it work !!!
I heavily modified your script and it works thanks !