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

How do I make my script teleport all people to the same people?

Hello, im a new developer and im working on my game.

I have this script which teleports players to GameBricks when the game starts. but, I have a huge problem! When the game starts the script teleports players to a different gamebrick each. I want them to all teleport to the same one. How can I do this?

heres the round start part of the script. the part that teleports the players.

function m_fnHandleActiveGame()
	if (ActiveRound.Value == true and RoundTime.Value == m_iTimerLength) then
		for i, player in ipairs(game.Players:GetChildren()) do
			max = Model.GameBricks:GetChildren()
			randomlocation = math.random(1,#max)
			m_fnTeleportTo(max[randomlocation], player, i)

All help is appreciated.

1 answer

This is because the spawn randomization is specified within the pairs loop, therefore for each Player iterated, the spawn will change. It's a quick and simple fix, simply allocate the chosen spawn within a variable, and define it outside of the pairs scope.

function m_fnHandleActiveGame() 
   if (ActiveRound.Value and RoundTime.Value == m_iTimerLength) then -- 
      local randomlocation = math.random(1,#max)
      for i, player in ipairs(game.Players:GetChildren()) do
         max = Model.GameBricks:GetChildren()
         m_fnTeleportTo(max[randomlocation], player, i)
      end
   end
end

2 comments

0

If you're wondering why line 2 has removed the == true portion, that is because conditionals default to true, therefore there isn't much a need to specify

0

thank you so much!

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