Leaderboard GUI only showing for the local player


my problem is you can only see your own stats, pls help

local player = game.Players.LocalPlayer

local playerTeam = player.Team

local templateFrame = script.Parent.Template

local newFrame = templateFrame:Clone()

local function RedColor()
	newFrame.BackgroundColor3 = Color3.new(0.909804, 0.176471, 0.309804)
	newFrame.Deaths.BackgroundColor3 = Color3.new(0.909804, 0.176471, 0.309804)
	newFrame.Kills.BackgroundColor3 = Color3.new(0.909804, 0.176471, 0.309804)
	newFrame.Username.BackgroundColor3 = Color3.new(0.909804, 0.176471, 0.309804)
end
local function BlueColor()
	newFrame.BackgroundColor3 = Color3.new(0.141176, 0.811765, 0.964706)
	newFrame.Deaths.BackgroundColor3 = Color3.new(0.141176, 0.811765, 0.964706)
	newFrame.Kills.BackgroundColor3 = Color3.new(0.141176, 0.811765, 0.964706)
	newFrame.Username.BackgroundColor3 = Color3.new(0.141176, 0.811765, 0.964706)
end

if playerTeam == game.Teams.Red then
	newFrame.Parent = script.Parent.RedTeamFrame
	newFrame.Visible = true
	newFrame.Username.Text.Text = player.Name
	newFrame.Kills.Text.Text = player:WaitForChild("leaderstats").Kills.Value
	newFrame.Deaths.Text.Text = player:WaitForChild("leaderstats").Deaths.Value
	RedColor()
elseif playerTeam == game.Teams.Blue then
	newFrame.Parent = script.Parent.BlueTeamFrame
	newFrame.Visible = true
	newFrame.Username.Text.Text = player.Name
	newFrame.Kills.Text.Text = player:WaitForChild("leaderstats").Kills.Value
	newFrame.Deaths.Text.Text = player:WaitForChild("leaderstats").Deaths.Value
	BlueColor()
end

player:WaitForChild("leaderstats").Kills:GetPropertyChangedSignal("Value"):Connect(function()
	newFrame.Kills.Text.Text = player:WaitForChild("leaderstats").Kills.Value
end)
player:WaitForChild("leaderstats").Deaths:GetPropertyChangedSignal("Value"):Connect(function()
	newFrame.Deaths.Text.Text = player:WaitForChild("leaderstats").Deaths.Value
end)

Well, by the looks of this it seems you’re only doing the LocalPlayer, have you tried looping every player in the game when they open the scoreboard/leaderboard?

As what @IAmTailerr said above, you are only applying this for the Local Player. To clone the template for everyone in the server, you need to loop through every player in the server.

Here is your updated code:

local Players = game:GetService("Players")
local Teams = game:GetService("Teams")

local templateFrame = script.Parent:WaitForChild("Template")

local function RedColor(frame)
	frame.BackgroundColor3 = Color3.new(0.909804, 0.176471, 0.309804)
	frame.Deaths.BackgroundColor3 = Color3.new(0.909804, 0.176471, 0.309804)
	frame.Kills.BackgroundColor3 = Color3.new(0.909804, 0.176471, 0.309804)
	frame.Username.BackgroundColor3 = Color3.new(0.909804, 0.176471, 0.309804)
end

local function BlueColor(frame)
	frame.BackgroundColor3 = Color3.new(0.141176, 0.811765, 0.964706)
	frame.Deaths.BackgroundColor3 = Color3.new(0.141176, 0.811765, 0.964706)
	frame.Kills.BackgroundColor3 = Color3.new(0.141176, 0.811765, 0.964706)
	frame.Username.BackgroundColor3 = Color3.new(0.141176, 0.811765, 0.964706)
end


local function cloneFrame(plrs, teamInstance)
	local newFrame = templateFrame:Clone()
	
	newFrame.Visible = true
	newFrame.Username.Text.Text = plrs.Name
	newFrame.Kills.Text.Text = plrs:WaitForChild("leaderstats").Kills.Value
	newFrame.Deaths.Text.Text = plrs:WaitForChild("leaderstats").Deaths.Value
	newFrame.Name = plrs.Name -- will be necessary when the player leaves
	
	if teamInstance == Teams.Red then
		newFrame.Parent = script.Parent:WaitForChild("RedTeamFrame")
		RedColor(newFrame)
	elseif teamInstance == Teams.Blue then
		newFrame.Parent = script.Parent:WaitForChild("BlueTeamFrame")
		BlueColor(newFrame)
	end
	
	plrs:WaitForChild("leaderstats").Kills:GetPropertyChangedSignal("Value"):Connect(function()
		newFrame.Kills.Text.Text = plrs:WaitForChild("leaderstats").Kills.Value
	end)
	
	plrs:WaitForChild("leaderstats").Deaths:GetPropertyChangedSignal("Value"):Connect(function()
		newFrame.Deaths.Text.Text = plrs:WaitForChild("leaderstats").Deaths.Value
	end)
end


local function removeFrame(plr)
	for _, descendants in pairs(script.Parent:GetDescendants()) do
		if descendants:IsA("Frame") and -- I assime the 'Template' is a Frame
			descendants.Name == plr.Name
		then
			descendants:Destroy()
		end
	end
end

for _, plrs in pairs(Players:GetPlayers()) do
	local plrTeam = plrs.Team
	cloneFrame(plrs, plrTeam)
end

Players.PlayerAdded:Connect(cloneFrame) -- this is for new players joining during the game
Players.PlayerRemoving:Connect(removeFrame) -- when the player leaves
1 Like

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