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.
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.
When its running in play mode:
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:
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!
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 do not make these spawn locations make these parts
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
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)