Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

PlayerAdded event not firing?

Hey guys, so here I come again with my hide-other-players script. It's in this current form:


	game.Players.PlayerAdded:Connect(function(plrVar)
	
	for _,player in pairs(game.Players:GetPlayers()) do
		
		--if player.UserId == plr.UserId then return end
		
		player.CharacterAppearanceLoaded:Connect(function(char)
						
			
				for _,cPart in pairs(char:GetDescendants()) do
				
					
					if cPart:IsA('Part') or cPart:IsA('BasePart') or cPart:IsA('MeshPart') then cPart.Transparency = 1 end	
				
				end		
				
				if char:WaitForChild('ForceField') then char.ForceField.Visible = false end
				char.Head.face.Transparency = 1
				char.Humanoid.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None
		end)
	end
end)

It's a long one, but all it should do is when an player joins, hide its character to me. Yes, it's in LocalScript for these purposes. But once I've wrapped the for loop into the PlayerAdded event, it's not running at all

Thanks in advance.

2 comments

0

or you can maintain transparency on the server and change transparency on the client which is much easier but ok

0

What? I want to hide the players only locally but idrg what you mean

1 answer

Solution 1. LocalScript indside the StarterGui -

local plr = game.Players.LocalPlayer

repeat wait() until plr.Character

local char = plr.Character
for _,cPart in pairs(char:GetDescendants()) do
	if cPart:IsA('Part') or cPart:IsA('BasePart') or cPart:IsA('MeshPart') then cPart.Transparency = 1 end  
end     
if char:WaitForChild('ForceField') then char.ForceField.Visible = false end
char.Head.face.Transparency = 1
char.Humanoid.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None

Solution 2. Script in ServerScriptService -

game.Players.PlayerAdded:Connect(function(plr)
	repeat wait() until plr.Character

	local char = plr.Character

	for _,cPart in pairs(char:GetDescendants()) do
		if cPart:IsA('Part') or cPart:IsA('BasePart') or cPart:IsA('MeshPart') then cPart.Transparency = 1 end  
	end     
	if char:WaitForChild('ForceField') then char.ForceField.Visible = false end
	char.Head.face.Transparency = 1
	char.Humanoid.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None
end)

Hope this works

5 comments

0

Why does it need to be in StarterGui? I have it in StarterPlayerScripts

0

That works too

0

That's the problem - it doesn't.

0

hmmm... did you try the ServerScriptService script

0

You may also need to try GetChildren() rather than GetDescendants()

This discussion is preserved as it was. New answers, comments, and votes are closed.