So this is a really simple script but I just cant figure it out can someone help me out.
local Rplayers = game.Players:GetChildren() local Mplayers = math.random(1,#Rplayers) local Aplayers = Rplayers[1] local Bplayers = Rplayers[2]
Thank you for helping me!
To get two random players
local players = game.Players:GetPlayers() local randomPlayer1 = players[math.random(#players)] local randomPlayer2 = players[math.random(#players)] while #players > 1 and randomPlayer1 == randomPlayer2 do players = game.Players:GetPlayers() randomPlayer2 = players[math.random(#players)] end
Here Duckie will elaborate some more for you. So in the roblox lua world to get players you use game.Players:GetPlayers()
local players = game:GetService("Players"):GetPlayers()
Now to get random players! First we get our first player and when we get out second player we make sure the first and second are not the same.
local players = game:GetService("Players"):GetPlayers() local playerone = players[math.random(1, #players)] local playertwo = players[math.random(1, #players)]--you don't need the 1 but it helps if playertwo == playerone then repeat local playertwo = players[math.random(1, #players)]--you don't need the 1 but it helps until playertwo ~= playerone end
There the end :D
To get a random player do this:
local rand = math.random(1,#game.Players:GetChildren()) local chosen = game.Players:GetChildren()[rand]
If this helped, clicked accept