I need some tips or links for the best way to do :
If i have the entire server teleported,But one is picked randomly by a function,I want him to NOT count with the people who got teleported. Basically,When this "randomPlayer" kills the rest of the players who got teleported i want something to happend(Ill script that),But any tips,Help ect?
This is NOT a request site. Please include any coding you have already done.
Anyways, to get a random player we can just use table[index]
. Since the GetPlayers()
method returns a table of all the players in the game, this will work. To get the actual random number, we use math.random()
, and the #
sign to make sure that number is in between 1 and the number of players in the game.
local players = game.Players:GetPlayers() local randomPlayer = players[math.random(1,#players)] print(randomPlayer.Name)
To detect when a player dies, we need to use the Died
event. To connect this event to all players, we just look through Players with a for
loop. Then, since we want to ignore the random player, check if the current player equals the random player, and if it doesn't, connect it to the event.
for i,v in pairs(game.Players:GetPlayers()) do if v ~= randomPlayer and v.Character then v.Character.Humanoid.Died:connect(function() print(v.Name.."died!") end) end end