I have a script that chooses a random player, but I don't understand how to give that random player a weapon. Any help would be appreciated :D
wait(10) dft = {} local plrs = #game:GetService('Players'):GetChildren() function GetPlayers() local c = game.Players:GetChildren() for i = 1, #c do table.insert(dft, c[i].Name) end end if plrs >= 2 then function Randomize() GetPlayers() local d = math.random(1, #dft) local s = d local m = Instance.new("Message", game.Workspace) m.Text = "The random player is ... "..dft[s].."!" wait(2) m:Remove() local rndm = game.Players:FindFirstChild(dft[s]) if (rndm ~= nil) then local Player = rndm.Character Player:MoveTo(Vector3.new(6, 13, 49)) end end while wait(20) do print("Done waiting.") print("Randomizing.") Randomize() break end else local h = Instance.new("Message") h.Parent = workspace h.Text = "Not enough players." wait(10) h:Remove() end plrs = #game:GetService('Players'):GetChildren()
I think you overthought this a little. All you have to do is select a random member of a table. I’ll leave an example below. You should also refresh the random player every time it is called, or it will give the same player each time. You can do that part yourself.
local Players = game.Players:GetPlayers() local Random = math.random(1, #Players)
The random variable is the same as your previous “Dft” variable. To give them a tool, just do something like this: (Clone the tool from elsewhere)
local Tool = game.ServerStorage:WaitForChild(“Tool”):Clone() Tool.Parent = Players[Random].Backpack