So I am making a game where you have to find the treasure chest and i want a series of random events to happen for example: a random player gets faster
but im trying to get the random player on this script right here
local Players = game:GetService("Players"):GetChildren()
game.Players.PlayerAdded:Connect(function(player)
wait(0.5)
player.CameraMaxZoomDistance = 17
wait(5)
local randomplayer = Players[math.random(1, #Players)]
randomplayer.Character.Humaniod.WalkSpeed = 30
end)
the other part is for max zoom distance the error is saying 11:32:28.929 ServerScriptService.MaxZoomDistance:8: invalid argument #2 to 'random' (interval is empty) - Server - MaxZoomDistance:8

2 comments
Mate, you're grabbing the in-game players way too early; there's nobody in the server at that time. That array will not update either. TL;DR: Grab the players within your PlayerAdded listener
i figured it out but ur comment still makes sense and will help me