PlayerAdded not firing

Welcome, I’m working on an in-game “server” system where everytime a player joins a folder which has a NumberValue as a child gets cloned, that NumValue then gets the ID of the player that just joined pasted into it.

It does get cloned, but not all the times, sometimes when I start a test with 3 Players only gets 1 folder cloned. The first player to join also seems to not get his folder cloned, same happens if I try on Roblox player.

local ServerData = game.ReplicatedStorage.MenuData.Servers
local player = game.Players.PlayerAdded:Wait()

local function generateServerCode()
	return string.format("%X", math.random(0, 0xFFFFFF))
end 

local function joinServer(player, x)
	local serverCode = generateServerCode()
	local playerFolder = player:FindFirstChild("leaderstats")
	
	local templateServerFolder = ServerData.ServerCode:Clone()
	templateServerFolder.Value = serverCode
	templateServerFolder.Parent = ServerData
	
	local player1Value = templateServerFolder:FindFirstChild("Player1")
	local UI = player.PlayerGui
	
	if player1Value then
		player1Value.Value = player.UserId
	end
	
	UI.MenuUi.MenuFrame.VPFme1.UserID.Value = player.UserId	
end

game.Players.PlayerAdded:Connect(function(player)
	print("A")
	joinServer(player)
	print("B")
end)

Hierarchy:
image

1 Like

Is this a Client script or a Server script?
I’m sure your issue is here:
image
Remove it.

3 Likes

Hello, sorry for the late response. It’s a Server script located in ServerScriptService. I tried what you said and it now works lol, thanks for the help!

1 Like

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