Infinite yield possible on "ReplicatedStorage:WaitForChild("PlayerList")"

I am unsure as to what is causing this, but for some reason what I wrote is getting interpreted as trying to access the replicatedstorage, while the script in of itself isn’t trying to access replicatedstorage at all. Below you may find the script responsible.

local replicatedStorage = game:GetService("ReplicatedStorage")
local iconEvent = replicatedStorage.IconChangeEvent
local Players = game:GetService("Players")



local function iconSwitch(player, teamArray, iconArray)
if teamArray[1] then
	local Playerlist = player.PlayerGui.WaitForChild("Playerlist")
	local Handler = Playerlist.Frame.Handler
	local Icon = Handler.Template.Icon
	if Icon then
		Icon.Image = iconArray[1]
	end
2 Likes

WaitForChild is a self method. It needs “:WaitForChild” not the .

:WaitForChild instead of .WaitForChild

This is because in Lua the : token references the parent class, and takes in the self argument automatically.

1 Like

thank you for assisting me with this!

1 Like

I honestly don’t know why it’s referencing ReplicatedStorage to be honest, kind of a weird behaviour, glad the solution worked for you though.

ah, whilst looking at my script, I realized I forgot to remove the old way in which I’ve assigned icons to the playerlist. Now that I’ve removed that old script, it seems to keep referencing ReplicatedStorage, without adding any icons…

Okay send the current script that is giving you issues

Here’s the entire script

local replicatedStorage = game:GetService("ReplicatedStorage")
local iconEvent = replicatedStorage.IconChangeEvent
local Players = game:GetService("Players")



local function iconSwitch(player, teamArray, iconArray)
	if iconArray[1] then
	local Playerlist = player.PlayerGui:WaitForChild("Playerlist")
	local Handler = Playerlist.Frame.Handler
	local Icon = Handler.Template.Icon
	Icon.Image = nil
	if Icon then
		Icon.Image = iconArray[1]
	end
elseif teamArray[2] then
		
		local Playerlist = player.PlayerGui:WaitForChild("Playerlist")
		local Handler = Playerlist.Frame.Handler
		local Icon = Handler.Template.Icon
		Icon.Image = nil
		if Icon then
			Icon.Image = iconArray[2]
		end
elseif teamArray[3] then
		local Playerlist = player.PlayerGui:WaitForChild("Playerlist")
		local Handler = Playerlist.Frame.Handler
		local Icon = Handler.Template.Icon
		Icon.Image = nil
		if Icon then
			Icon.Image = iconArray[3]
		end
elseif teamArray[4] then
		local Playerlist = player.PlayerGui:WaitForChild("Playerlist")
		local Handler = Playerlist.Frame.Handler
		local Icon = Handler.Template.Icon
		Icon.Image = nil
		if Icon then
			Icon.Image = iconArray[4]
		end
elseif teamArray[5] then
		local Playerlist = player.PlayerGui:WaitForChild("Playerlist")
		local Handler = Playerlist.Frame.Handler
		local Icon = Handler.Template.Icon
		Icon.Image = nil
		if Icon then
			Icon.Image = iconArray[5]
		end
end
	
end

iconEvent:FireAllClients(iconSwitch)

Can you please copy and paste it, instead of a screenshot

I have edited the last post to include the code.

Humor me real quick. Replace replicatedStorage.IconChangeEvent in line 2 to be

replicatedStorage:WaitForChild("IconChangeEvent")


unfortunate

Okay so real quick, you can’t send a function through the FireAllClients method, that just won’t work. FireAllClients needs parameters. The function you have should be on the client side (eg localscript) and should be receiving the event.

iconEvent.OnClientEvent:Connect(iconSwitch)

alright, so what I’ve gathered is that I should copy and paste the function onto my localscript, and at the bottom of the function, post your iconEvent.OnClientEvent:Connect(iconSwitch)?

Yes, and then make sure in the server script you’re actually firing to all clients when you want the code to run

how would I do this? I’m rather new to scripting, so apologies for my clueless attitude when it comes to this

Should this script work as I have intended it to? Since I’m trying switch icons, and I tried testing this alone, and I came up empty handed…

As in, no icons at all despite the shift to localscript

I found the solution to this. It was simply a matter of deleting an old script that led to nowhere.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.