It’s because the Players variable will be defined by the players in the server at the moment the server opens so it will error because there isn’t any player
local Players = game:GetService("Players")
-- Wait for the Players service to load if it's not available yet
while not playersService do
Players= game:WaitForService("Players")
end
local players = playersService:GetPlayers()
if #players > 0 then
local pickedPlayer = players[math.random(1, #players)]
-- your code goes here
else
print("No players found.")
end