Teleport Handler Issue

Hello peeps, I’m trying to create a handler script that should do the following:

  • Inside a Folder, there are destination parts with a certain name (For example, I’m going to use the name “Station”) that can go from 1 to beyond.

image

The Handler acts like this:

wait(3)

local stationSpawnList = game.Workspace.Stations
local station = script.Parent.BG.ScrollingFrame


function makeSpawns()
	
	for i,v in pairs(stationSpawnList:GetChildren()) do
		local spawnButton = script.TextButton:Clone()
		spawnButton.Name = v.Name
		spawnButton.Text = v.Name
		
		spawnButton.Parent = station
	end
end

makeSpawns()

-the handler should add a button with another script, using a template from the handler itself. The Button will be added inside a scrolling frame when it detects the destination part.

image

When its running in play mode:
image

The Handler is all good. The Main problem here is, once it creates the button, the script inside of it doesnt want to teleport me.

Here’s the code used inside the button:

local stationSpawnList = game.Workspace.Stations
local value = stationSpawnList.Station
script.Parent.MouseButton1Down:Connect(function()
	game.Players.LocalPlayer.character.LowerTorso.CFrame = value.CFrame
end)

The Error I receive when I run it in play mode is like this:
image

I have tried to use GetChildren for it to get the destination, but instead, wants to take the entire folder, containing every destination( I realized it after 20-30 minutes of trying with this method, yea im dum)

If theres any other solution, please tell me, it will be highly appreciated!
Thanks in advance!

1 Like

Is there any errors in the output?

It says “Station is not a valid member of the folder”

I forgot to say that, Im gonna add it the main post.

Yeah you’re trying reference a part that ins’t there. Try changing

to

local value = stationSpawnList.Station1

Yes, like that it will work. But only for Destination1, and the Button1 aswell, same for the other buttons, will go to destination1

local stationSpawnList = workspace.Stations
local value = math.random(1,#stationSpawnList)
script.Parent.MouseButton1Down:Connect(function()
	game.Players.LocalPlayer.Character.HumanoidRootPart.CFrame = value.CFrame
end)

This code should work and it will pick a random part inside of the folder :slight_smile: do not make these spawn locations make these parts

That’s it, because how do you want it to spam at “Station” when it’s not even valid.

Now I receive an error attempting to get a leght of a instance value, oh yeah, changed the spawns to parts aswell

ok try this

local stationSpawnList = workspace.Stations
script.Parent.MouseButton1Down:Connect(function()
       local chosenSpawn = math.random(1,#stationSpawnList)
	game.Players.LocalPlayer.Character.HumanoidRootPart.CFrame = chosenSpawn.CFrame
end)

and you deleted the spawn locations and made them parts right?

  1. yes, I removed the spawn, and created new parts
  2. as soon as I press the teleport button to one of the destinations, I receive the same error as before

try this

local Player = game.Players.LocalPlayer
repeat wait() until Player.Character
local c = Player.Character
local stationSpawnList = workspace.Stations
script.Parent.MouseButton1Down:Connect(function()
       local chosenSpawn = math.random(1,#stationSpawnList)
	c.HumanoidRootPart.CFrame = chosenSpawn.CFrame
end)

these parts are inside of the folder right? and there are only parts in the folder nothing else

Nothing else is in the folder other than the destination parts

Again, same error

show me your stations folder please

image

As said, nothing else other than the destinations

try this

local Player = game.Players.LocalPlayer
repeat wait() until Player.Character
local c = Player.Character
local spawns = workspace.Stations
script.Parent.MouseButton1Down:Connect(function()
	c.HumanoidRootPart.CFrame = [math.random(1,#spawns)].CFrame
end)

this leads to the same error as before, Im afraid…

This might work?

local stationSpawnList = game.Workspace.Stations
script.Parent.MouseButton1Down:Connect(function()
	game.Players.LocalPlayer.Character:WaitForChild('HumanoidRootPart').CFrame = stationSpawnList:FindFirstChild(script.Parent.Text).CFrame
end)

Yes, this actually made it work!
Thanks! Learned my lesson.

1 Like

Maybe do stationSpawnList[button.Text], since the text of the buttons corresponds to the name of the station.

quick issue with that code… if someone mistypes the code might break