could anyone help me figure what is wrong with my script? I am getting no errors in output and whenever i put a print with something in the local function, nothing is printed so i’m so confused!
if you need more info just ask
thank you.
server script
for i, plr in getActivePlayers() do
local char = plr.Character
if not char then continue end
local CustomCamera = game.ReplicatedStorage.RemoteEvents.CustomCamera
CustomCamera:FireClient(plr)
end
local script
local CustomCamera = game.ReplicatedStorage.RemoteEvents.CustomCamera
local function CustomCam()
Camera.CameraType = Enum.CameraType.Custom
Camera.CameraSubject = game.Players.LocalPlayer.Character.Humanoid
end
CustomCamera.OnClientEvent:Connect(CustomCam)
Might be an issue with how “getActivePlayers” is defined. Have you added prints inside for i, plr in getActivePlayers() do this for loop to ensure players are being iterated over?
Always use GetService please
Data could’ve not loaded intime/connection were not initiated in time.
Also please cache variables in upper values and avoid this abomination
Use waitforchild for client variables.
ReplicatedStorage are 100% not loaded if code is in ReplicatedFirst
Make client ping server via remote event that it is ready to recive variables etc.
Kick player if it has not pinged server after 100 seconds.
local activePlayers = {}
local function isPlayerInTable(player)
for i, plr in activePlayers do
if plr == player then
return true
end
end
return false
end
local function getActivePlayers()
return activePlayers
end
MenuPlayerAdd.OnServerEvent:Connect(function(player)
if not isPlayerInTable(player) then
table.insert(activePlayers, player)
end
MenuPlayerAdd:FireAllClients(player.Name)
end)
MenuPlayerRemove.OnServerEvent:Connect(function(player)
for i, plr in activePlayers do
if plr == player then
table.remove(activePlayers, i)
break
end
end
MenuPlayerRemove:FireAllClients(player.Name)
end)
here is the active players menu part of the script. I have also tried replacing the getactiveplayers() with players:getplayers() and it did not work.