So i have this server script which works with FE:
function idle_music(action)
if action == "add" then
print("adding")
local random = lobby_songs[math.random(1, #lobby_songs)]
local replicatedStorage = game:GetService("ReplicatedStorage")
for _, p in pairs (game.Players:GetPlayers()) do
print("looping through players")
if p:FindFirstChild("PlayerGui"):FindFirstChild("Muusic") then -- checking for screen gui
print("There already is a musicGui")
else
print("There is no musicGui... Adding one rn")
local musicGui = replicatedStorage:WaitForChild("MusicGui"):Clone()
musicGui.Name = "Muusic"
musicGui.Parent = p.PlayerGui
end
if p and p:FindFirstChild("PlayerGui"):WaitForChild("Muusic"):FindFirstChild("IdleSound") == nil then
print(p.Name.. " didnt find a sound")
local sound = Instance.new("Sound", p:FindFirstChild("PlayerGui"):WaitForChild("Muusic"))
sound.Name = "IdleSound"
sound.SoundId = "rbxassetid://"..random
sound.Looped = true
sound.Volume = 0.4
sound:Play()
print("dun")
print("fine")
else
print(p.Name.. " found a sound")
end
end
else
for _, item in pairs(game.Players:GetPlayers()) do
if item and item:WaitForChild("PlayerGui", 5):GetChildren() then
local todel = item:FindFirstChild("PlayerGui"):WaitForChild("Muusic"):WaitForChild("IdleSound", 2)
if todel then
todel:Destroy()
end
end
end
end
end
This is just a function that's called every once in a while and it worked perfectly before but now when I want to add a screen gui to a player gui thourgh a server script it always says "Infinite yield possible in playerName:"WaitForChild(something)"
And it does print "adding" but it never prints "looping through players"
Why does this happen and how can I fix?
