Why is my player added not firing?

Is the script initially disabled then you eventually reenable it? I’ve tested the code in studio and it seems to work fine…? The PlayerAdded event is firing when I run it inside of studio.

1 Like

Then you have to say that you did try them and that it didn’t work, not “it won’t work because.”

that is not the issue worm. idk why you cant get this fact, the print statement IS PRINTING AFTER THE WFC, so it is not yielding the code.

Simply remove the WaitForChild as it is not needed, that should fix the issue, as it will wait for no reason as it already exists.

1 Like

This is not necessary as workspace is a built-in global variable which is a reference to the Workspace service.

1 Like

You can try making a bilboardGui and u wont have to do the CharAdded

um? what… no the type of UI is not the problem, I have the exact script in a second game of mine and that one works fine but not for this one

nope, still nothing

30 charsssssss

its not disabled for me but I can try it inside the actual game

WaitForChild isn’t the issue, assuming that its already existing. When using :WaitForChild() for something that already exists, the time for it to run isn’t any different. But yes, it’s unneeded most of the time in a server script

Your player might be loading in before the PlayerAdded event. Replace your script with this:

local overheadUI = game:GetService("ServerStorage"):WaitForChild("OverheadUI")

local function addOverhead(player, char)
	if player.UserId == 1242035307 then
		local clone = overheadUI:Clone()
		clone.Parent = workspace	
		clone.Adornee = char.Head
		clone.Main.Label.Text = "Lead Programmer"
	elseif player.UserId == 21835695 then
		local clone = overheadUI:Clone()
		clone.Parent = char.Head
		clone.Main.Label.Text = "Group Owner"
	elseif player.UserId == 303373309 then
		local clone = overheadUI:Clone()
		clone.Parent = char.Head
		clone.Main.Label.Text = "Founder"
	elseif player:GetRankInGroup(4946462) == 3 then
		local clone = overheadUI:Clone()
		clone.Parent = char.Head
		clone.Main.Label.Text = "Tester"
	end
end

for _,player in pairs(game.Players:GetPlayers()) do
	if player.Character then
		addOverhead(player, player.Character)
	end
	
	player.CharacterAdded:Connect(function(char)
		addOverhead(player, player.Character)
	end)
end

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(char)
		addOverhead(player, char)
	end)
end)

ChatService.SpeakerAdded:Connect(function(speakerName)
	local speaker = ChatService:GetSpeaker(speakerName)		
	local player = game.Players[speakerName]

	if player.UserId == 1242035307 then
		speaker:SetExtraData("Tags", {{TagText = "Lead Programmer", TagColor = Color3.fromRGB(0, 255, 0)}})
		speaker:SetExtraData("ChatColor", Color3.fromRGB(0, 255, 0))
		speaker:SetExtraData("NameColor", Color3.fromRGB(0, 255, 0))
	elseif player.UserId == 21835695 then
		speaker:SetExtraData("Tags", {{TagText = "Group Owner", TagColor = Color3.fromRGB(255, 255, 255)}})
	elseif player.UserId == 303373309 then
		speaker:SetExtraData("Tags", {{TagText = "Founder", TagColor = Color3.fromRGB(255, 255, 255)}})
	elseif player:GetRankInGroup(4946462) == 3 then
		speaker:SetExtraData("Tags", {{TagText = "Tester", TagColor = Color3.fromRGB(255, 255, 255)}})
	end
end)
2 Likes

Actually, it would appear this is the issue. By the time it waits for the “OverheadUI” instance to be added in and then it registers the PlayerAdded event, the player already exists, therefore, the event will not be fired.

However, it appears there is more code in the same script that you have not shown us making it impossible for us to verify the issue. For example, it appears you are also waiting on the ChatService to load in before registering the PlayerAdded event too. Next time please post the entire contents of your script rather than making everyone guess.

3 Likes

It’s possible the child is being added after the first player joins. I suggest iterating through existing players in the game with the same function you connected to PlayerAdded. I’m not sure how you’re creating overheadUI, but if possible I would recommend losing the WaitForChild. Hope this helps!

1 Like

will do

30000 charsssssssssssss

The code I posted does just that.

so, as it turns out it really was just a studio issue, thanks for everyone who helped and suggested doing the overheadUI method.

uhhh ok cool :+1: