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
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
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
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