Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
v_Lzke 0
4 years ago

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

Log in to vote
0
Answered by
Ziffixture 6913 Moderation Voter Community Moderator
4 years ago

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
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 Ziffixture 6913 — 4y
0
thank you so much! v_Lzke 0 — 4y
Ad

Answer this question