So how would I make a script where a random player is chosen and given a tool. If that player dies, the tool will be given randomly to someone else
function changepotato()
local players = game:GetService(“Players”)
local randomplayer = players[math.random(1, #players)]
local potato = game:GetService(“ServerStorage”)[“Pass Potato”]
local AllPlayers = game:GetService("Players"):GetPlayers()
local RandomPlayer = math.random(1, #AllPlayers)
print(AllPlayers[RandomPlayer])
Assuming you are attempting to make a rendition of hot potato, you can handle deaths yourself (ie. when the potato explodes etc, kill the player holding it & assign a new player to hold it)
local PS = game:GetService("Players")
local SS = game:GetService("ServerStorage")
local function ChangePotato()
local randomPlayer = PS:GetPlayers()[math.random(1, #PS:GetPlayers())]
local potatoClone = SS["Pass Potato"]:Clone()
potatoClone.Parent = randomPlayer.Backpack
randomPlayer.Died:Connect(ChangePotato)
end
ChangePotato()