This question sounds weird and possibly even incredibly obvious-- but let me explain.
This script here, works in studio-- but as you know Roblox actually takes time to load the things I need in a server-- which creates the problem
local function RandomPlayer()
local players = game.Players:GetPlayers()
if #players > 0 then
return players[math.random(#players)]
end
end
local FacePlayer = coroutine.wrap(function()
-- wait(5)
while wait(0.1) do
local Plr = RandomPlayer()
local Chr = Plr.Character
local TorsoPos = Chr:WaitForChild("Torso").Position
local Gyro = Boss.Core.BodyGyro
Gyro.CFrame = CFrame.new(Boss.Core.Position, TorsoPos)
Gyro.MaxTorque = Vector3.new(math.huge, math.huge, math.huge)
Gyro.P = 999999
end
end)
FacePlayer()
The problem is in the RandomPlayer() function-- I don't know how to write a check to make sure there are players to randomly choose as Roblox loads everything-- without having to just stop the script for 5 seconds or having ALL MY ATTEMPTS OF FIXING IT JUST TIME OUT AND STOP THE SCRIPT ANYWAY! >;0
Also this has a fine habit of breaking if your torso doesn't exist because you say-- fell off the map Ou0; Something that I'm also having a hard time writing a check for.
Yes, I know there are other things wrong with this-- but those problems I want to solve myself. For now I'd like help with actually waiting for players ;o;

3 comments
Well first off, it should be 'return players[math.random(#players, 1)]'
It doesn't matter.
I don't need the 2nd arg for this :P