Custom Leaderboard Issue

I have been having a constant issue while trying to make a GUI. It worked for a little bit, but when testing with a friend it only showed the display of my data ( name, group, group rank ) and not his. I don’t see the issue with the script, and a different script uses SetCoreGuiEnabled to disable default leaderboard so don’t worry about that.

I’ve tried numerous methods, and none of them are working. Pretty stressful, not gonna lie.

local ItemTemplate = game:GetService("ReplicatedStorage").Player1

local GroupIDs = {
	["Rome"] = 4165387,
	["Urbanae"] = 6892611,
	["XII"] = 6892171,
	["Praetorian"] = 6892505
}
local ImageIDs = {
	["Rome"] = "rbxassetid://6924766053",
	["Urbanae"] = "rbxassetid://2",
	["XII"] = "rbxassetid://1",
	["Praetorian"] = "rbxassetid://3",
}

game.Players.PlayerAdded:Connect(function(Player)
	local NewItem = ItemTemplate:Clone()
	local Group = NewItem:WaitForChild("Group")
	local Rank = NewItem:WaitForChild("Rank")
	local Username = NewItem:WaitForChild("User")
	NewItem.Parent = script.Parent.Leader.PlayerList
	NewItem.Name = Player.Name
	Username.TextScaled = true
	Username.Text = Player.Name

	for GroupName, GroupID in pairs (GroupIDs) do
		if Player:IsInGroup(GroupID) then
			Group.Image = ImageIDs[GroupName]
			Rank.Text = Player:GetRoleInGroup(GroupID)
		end
	end
end)

game.Players.PlayerRemoving:Connect(function(Player)
	local Frame = script.Parent.Leader.PlayerList[Player.Name]
	if Frame then
		Frame:Destroy()
	end
end)

This is a local script, btw

No errors by the way in developer console.

Maybe because the localscript only fires for the player that joins. Add a RemoteEvent in replicatedstorage that adds the gui, then call it from your localscript using :FireServer() passing through any data (player stats, name, etc)

FireServer() passes through the player’s value by default. So in your script you will need to write

game.ReplicatedStorage.Event.OnServerEvent:Connect(function(player,any other arguments here)

Also localscripts don’t need a PlayerAdded event as it already fires when a player joins

im trying a different method i saw on the forum

it just uses a while loop to constantly look

The issue now is just making it so when the player leaves, the GUI object created for that player gets destroyed. How could I do this? This is what I tried, and it doesn’t work.

game.Players.PlayerRemoving:Connect(function(Player)
	local frame = script.Parent
	
	if frame:FindFirstChild(Player.Name) then
		frame[Player.Name].Parent = nil
	end
	
end)

You can add the item to Debris

	if frame:FindFirstChild(Player.Name) then
		game:GetService("Debris"):AddItem(frame[Player.Name],0) -- 0 second delay
	end

Didn’t work. Still just keeps the GUI in the game even after they leave. yet again, 0 errors in F9