I tried to make a script where it chooses a random person in the server and gives them a weapon. It works with a 1 Player server but not with a server with more than one player. Here’s the script:
local playertable = {}
local repstore = game:GetService(“ReplicatedStorage”)
local weapon = repstore.ClassicSword
local plrs = game.Players
while wait(1) do
local chosenplr = plrs:GetChildren()[math.random(1, #plrs:GetChildren())]
local murderweapon = weapon:Clone()
murderweapon.Parent = chosenplr.Backpack
end
Ok, I made a script which is an example of how this is works (It works i tested it) here is the script:
And I figured out what was wrong. You forgot to see if the amount of players was 0 (when the server first starts)
while wait(1) do
local Players = game.Players:GetPlayers()
if #Players ~= 0 then -- before you didn't check if the amount of players is 0
local RandomPlayer = Players[math.random(1,#Players)]
print(RandomPlayer)
end
end