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

How to make a script that teleports two random players?

Asked by 3 years ago

So, I'm extremely new with scripting and I've managed to create an elevator game. (Somehow) I'm trying to create a script that when the elevator doors open it'll randomly choose two players to enter the floor and before the time for the elevator is up, it'll teleport them back onto the elevator. I could really use some help on how to go about doing this because I have no idea where to even start. I'm not looking for someone to do it for me, but to help me grasp an understanding on how to go about writing it. Any tutorials you may have in your archive will help tremendously!

2 answers

Log in to vote
2
Answered by
Soban06 410 Moderation Voter
3 years ago
Edited 3 years ago

Since you haven't posted any script regarding what you have done, I will tell you how to select any random 2 players from the game.

So here it is:

01wait(3) -- We add this wait to make sure the script loads after the player has loaded
02warn("Script started")
03local PlayersInGame = {}
04 
05for i, player in pairs(game.Players:GetPlayers()) do
06    if player then
07        table.insert(PlayersInGame, player)
08        -- We insert all the players which are in the game into the table
09    end
10end
11 
12-- We create this function to see if that player has already been seelcted so we don't select him again'
13local function CheckIfPlayerIsInTable(tab, name)
14    local found = false
15    for i, v in pairs(tab) do
View all 44 lines...

Hope this helps. If you have any questions regarding this answer feel free to comment below.

0
Couldn't upload scripts at the time, but thank you for the script I appreciate it. I actually should've made it clearer in my post that I wasn't looking for a request. I was hoping that some users would have some helpful videos on how to script and how to go about understanding how to make this. My apologies for the misinformation on my behalf! I'll learn a lot from the scripts given. Thank you. ScarlettPhoenixx 2 — 3y
0
You're Welcome. If this answer helped you, consider accepting. Soban06 410 — 3y
Ad
Log in to vote
0
Answered by 3 years ago

this is not a request site so next time please come with a script for us to fix/help you with.

01game.Players.PlayerAdded:Connect(function()
02    if #game.Players:GetPlayers() > 5 then -- checks for at least 5 players before game picks 2 random players (can remove this, just here to show you that its picking 2 random players or i recomend changing it to 2 players so it doesn't error)
03 
04        local playerList = game.Players:GetPlayers()
05        local chosenPlayer1 = playerList[math.random(1, #playerList)]
06        table.remove(playerList, table.find(playerList, chosenPlayer1))
07 
08        local chosenPlayer2 = playerList[math.random(1, #playerList)]
09        table.remove(playerList, table.find(playerList, chosenPlayer2))
10    end
11end)
0
Couldn't upload scripts at the time, but thank you for posting, I appreciate it. I wasn't asking for a request. I said I didn't want others to do it for me, but to offer tutorials that can help understand how to script in order to go about making this. I should have made that clearer in my post, my apologizes ScarlettPhoenixx 2 — 3y

Answer this question