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

Random map chooser then teleport all players to a specific part on the map script not working?

local t = game.Workspace.ScreenGui.TextBox
while wait (1) do
if game.Workspace.ScreenGui.TextBox.Text == "The Map Chosen Is..." then
	game.Workspace["Starting..."].Disabled = true
	
	local maps = game.ReplicatedStorage.Maps:GetChildren()

    local select = table.remove(maps,math.random(#maps))
wait (6)
    t.Text = ""..select.Name
select.Parent = game.Workspace

end


target = CFrame.new(game.Workspace.(select.Hehe.Position))
for i, player in ipairs(game.Players:GetChildren()) do
   --Make sure the character exists and its torso exists
 if player.Character and player.Character:FindFirstChild("Torso") then
   --add an offset of 5 for each character
   player.Character.Torso.CFrame = target + Vector3.new(0, i * 5, 0)
end
end
end

The script is supposed to select a random map, then put it in the Workspace. After that, the script is supposed to teleport all the players to the specific brick on the map. This whole script does not work. Can anyone edit it for me?

5 comments

0

Line 4: Not only have you made an object with dots in in its name but you are disabling a script (I smell an error there). Is that script by any chance "Starting..."?

0

Nope, no errors. This script starts because of Starting...

0

Are you sure? Line 16 looks a bit off.

0

Whats wrong with it?

0

game.Workspace.(select.Hehe.Position) What are you even trying to do there? And how did that not produce a syntax error?

1 answer

Ok, so there are a number of things wrong here:

1: You have a ScreenGui in Workspace. They should go in StarterGui (but do not edit that version, instead loop through all the Players and check to see if they have the interface and, if so, set it that way.

2: At line 3 you are checking the current text of the TextBox to determine if the game needs updating. Although strictly speaking valid, it is a poor choice. Either store it in a StringValue or a ModuleScript (this script is a prime example of something which make a good ModuleScript)

3: At line 11 you reparent the selection to Workspace. Although valid, any changes to the environment will persist. Clone the selection to ensure this does not happen. Also, store maps in ServerStorage for reduced loading times and extra security (and scripts should go in ServerScriptService).

4: Line 16: There is a syntax error at game.Workspace.(select.Hehe.Position). I believe this should be select.Hehe.Position.

5: Line 17: When getting all the players, use Players:GetPlayers() for added security.

2 comments

0

@Sward - The ScreenGui is where it is supposed to be. I have another screenGui in the playerGui and there is a script where the text button is. The script tells the Text to copy the text in the other Gui...

0

Well in that case why not simply make it a StringValue? It would be less unusual than having a ScreenGui in the Workspace whose only function is to be mirrored.

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