Gui leaderstat issue

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    what the gui to be for each player
  2. What is the issue? Include screenshots / videos if possible!
    the local script is cloned into each player but only references the current local players leader stats

want the gui to reflect the players individual leader stat accross the server

wait(.5)
while wait(0.1) do
	script.Parent.Text = ""..game.Players.LocalPlayer.leaderstats.Kills.Value
end

Have also tried a conbination of firing server and client remotes but cant seem to get it right


Screenshot 2022-07-31 064049

1 Like

Have also seen a tabling method to achieve this but cant understand how to apply it

1 Like

You don’t have to concatenate it with an empty string. Also, while wait() do is a bad practice since it’s non-idiomatic (meaning it doesn’t follow the language’s conventions, wait() returns a number, not a boolean)

All that aside, I need more information to work with. This is not enough, as this script portion alone looks fine.

1 Like

Hi!

Connect a function to when the leaderstat changes value.

local LocalPlayer = game:GetService("Players").LocalPlayer
local Leaderstats = LocalPlayer:WaitForChild("leaderstats")
local Stat_Kills = Leaderstats:WaitForChild("Kills")

Stat_Kills:GetPropertyChangedSignal("Value"):Connect(function()
	script.Parent.Text = Stat_Kills.Value -- This updates the text everytime the Kills-value changed
end)
script.Parent.Text = Stat_Kills.Value -- This sets the default Text to be equal to the current Kills-value
1 Like
game.Players.LocalPlayer.leaderstats.Kills:GetPropertyChangedSignal:Connect(function()
     script.Parent.Text = tostring(game.Players.LocalPlayer.leaderstats.Kills.Value)
end)

Eliminate the while wait as a whole and just replace it with what I sent

image

Hey mate i get this error

hi Mate i tried this script also but the outcome was the same as my first picture that shows both both players are 0 on the left and on the right side player they are both 2 any further ideas?

game.Players.LocalPlayer.leaderstats.Kills:GetPropertyChangedSignal('Value'):Connect(function()
	script.Parent.Text = tostring(game.Players.LocalPlayer.leaderstats.Kills.Value)
end)

‘’’

local Enumeration = Enum
local Game = game
local Script = script
local Players = Game:GetService(“Players”)
local Teams = Game:GetService(“Teams”)
local GreenTeam = Teams.Green
local BlueTeam = Teams.Blue

local TeamsGui = Script:FindFirstAncestorOfClass(“ScreenGui”)
local GreenTeamFrame = TeamsGui:FindFirstChild(“GreenTeamFrame”)
local BlueTeamFrame = TeamsGui:FindFirstChild(“BlueTeamFrame”)

local TeamFrames = {[GreenTeam] = GreenTeamFrame, [BlueTeam] = BlueTeamFrame}

for _, Team in ipairs(Teams:GetTeams()) do
local function OnTeamPlayerAdded(Player)
print(TeamFrames[Player.Team])
local TeamFrame = TeamFrames[Player.Team]
if not TeamFrame then return end

	local PlayerImage = TeamFrames[Player.Team]:FindFirstChild(Player.Name)
	local PlayerImage2 = TeamFrames[Player.Team]:FindFirstChild(Player.Name)

	if not PlayerImage then
		local Success, Result = pcall(function() return Players:GetUserThumbnailAsync(Player.UserId, Enumeration.ThumbnailType.HeadShot, Enumeration.ThumbnailSize.Size420x420) end)
		if not (Success and Result) then warn(Result) return end
		PlayerImage = Instance.new("ImageLabel")
		PlayerImage.Name = Player.Name
		PlayerImage.Size = UDim2.new(.15, 0, 1, 0)
		PlayerImage.Image = Result
		PlayerImage.Parent = TeamFrames[Player.Team]
		PlayerImage2 = Instance.new("TextLabel")
		PlayerImage2.Name = "Kills"
	    PlayerImage2.Size = UDim2.new(.3, 0, 1.5, 0)
	    PlayerImage2.Text = "0"
	    PlayerImage2.TextSize = 14
	    PlayerImage2.BackgroundTransparency = 1
	    PlayerImage2.TextColor3 = Color3.new(1, 1, 1)
	    PlayerImage2.Parent = PlayerImage
	    PlayerImage.BackgroundColor3 = Player.TeamColor.Color
		local killscript = script.Parent.Killsscript:Clone()
		killscript.Parent = PlayerImage2
		killscript.Disabled = false
		

		
end
	
	
	

end

local function OnTeamPlayerRemoved(Player)
local TeamFrame = TeamFrames[Team]
if not TeamFrame then return end
local PlayerImage = TeamFrame:FindFirstChild(Player.Name)
if PlayerImage then PlayerImage:Destroy() end

end






Team.PlayerAdded:Connect(OnTeamPlayerAdded)
Team.PlayerRemoved:Connect(OnTeamPlayerRemoved)
for _, Player in ipairs(Team:GetPlayers()) do
	OnTeamPlayerAdded(Player)
end

end
‘’’

hey mate i added the script im using to create the teams gui with the image , textlabel , and local script.

Appears that as the local script is clone it is only looking at the local player and not the player the image is for example.

for _, player in pairs(game:GetService('Players'):GetPlayers()) do
	if player:IsA('Player') then
		if player:FindFirstChild('leaderstats', false) then
			local leaderstats = player:FindFirstChild('leaderstats', false)
			if leaderstats:IsA('Folder') then
				if leaderstats:FindFirstChild('Kills', false) then
					local kills_val = leaderstats:FindFirstChild('Kills', false)
					if kills_val:IsA('ValueBase') then
						kills_val:GetPropertyChangedSignal('Value'):Connect(function()
							script.Parent.Text = tostring(kills_val.Value)
						end);
					end;
				end;
			end
		end;
	end;
end;

Try this

Hi Mate thank you for your help seem to me getting closer this time it updated all of the leaderstats for the players when i only killed the player once as you will see in the top right corner of each screen the green does say 1 it is hard to see in the photo what are your thoughts ?

You could add a check to see what team the player(s) are on and if they are on that team THEN update the value

thank you for your help however im only new to scripting where would i add it in ?

for _, player in pairs(game:GetService('Players'):GetPlayers()) do
	if player:IsA('Player') then
		if player:FindFirstChild('leaderstats', false) then
			local leaderstats = player:FindFirstChild('leaderstats', false)
			if leaderstats:IsA('Folder') then
				if leaderstats:FindFirstChild('Kills', false) then
					local kills_val = leaderstats:FindFirstChild('Kills', false)
					if kills_val:IsA('ValueBase') then
						kills_val:GetPropertyChangedSignal('Value'):Connect(function()
							if player.Team == game:GetService('Teams'):FindFirstChild('TEAM_NAME_HERE', false) then --// Enter your team name here
								script.Parent.Text = tostring(kills_val.Value)
							end;
						end);
					end;
				end;
			end
		end;
	end;
end;

thanks mate yeah once you add the teams filter if the player is not the green team for example and you set it to blue in the script nothing happens. If you are on the blue team and it is set to blue it does as before update all four stats as above. Think it is an issue that the same local script is getting cloned into every please even if they are on different team

I can only really help further if I know mainly how you have this set up.

ok cool i will show you

local Enumeration = Enum
local Game = game
local Script = script
local Players = Game:GetService(“Players”)
local Teams = Game:GetService(“Teams”)
local GreenTeam = Teams.Green
local BlueTeam = Teams.Blue

local TeamsGui = Script:FindFirstAncestorOfClass(“ScreenGui”)
local GreenTeamFrame = TeamsGui:FindFirstChild(“GreenTeamFrame”)
local BlueTeamFrame = TeamsGui:FindFirstChild(“BlueTeamFrame”)

local TeamFrames = {[GreenTeam] = GreenTeamFrame, [BlueTeam] = BlueTeamFrame}

for _, Team in ipairs(Teams:GetTeams()) do
local function OnTeamPlayerAdded(Player)
print(TeamFrames[Player.Team])
local TeamFrame = TeamFrames[Player.Team]
if not TeamFrame then return end

	local PlayerImage = TeamFrames[Player.Team]:FindFirstChild(Player.Name)
	local PlayerImage2 = TeamFrames[Player.Team]:FindFirstChild(Player.Name)

	if not PlayerImage then
		local Success, Result = pcall(function() return Players:GetUserThumbnailAsync(Player.UserId, Enumeration.ThumbnailType.HeadShot, Enumeration.ThumbnailSize.Size420x420) end)
		if not (Success and Result) then warn(Result) return end
		PlayerImage = Instance.new("ImageLabel")
		PlayerImage.Name = Player.Name
		PlayerImage.Size = UDim2.new(.15, 0, 1, 0)
		PlayerImage.Image = Result
		PlayerImage.Parent = TeamFrames[Player.Team]
		PlayerImage2 = Instance.new("TextLabel")
		PlayerImage2.Name = "Kills"
	    PlayerImage2.Size = UDim2.new(.3, 0, 1.5, 0)
	    PlayerImage2.Text = "0"
	    PlayerImage2.TextSize = 14
	    PlayerImage2.BackgroundTransparency = 1
	    PlayerImage2.TextColor3 = Color3.new(1, 1, 1)
	    PlayerImage2.Parent = PlayerImage
	    PlayerImage.BackgroundColor3 = Player.TeamColor.Color
		local killscript = script.Parent.Killsscript:Clone()
		killscript.Parent = PlayerImage2
		killscript.Disabled = false
		

		
end

This is basically how the teams are created when selected its floor is that i am cloning a local script but it goes into all players weather they are on green or blue. there is am image label that is created in the team frame. then there is a text label that parants that and then i clone the local script to parant the textlabel which ends up like the explorer picutre i added at the top when the game is run

Yo, what does your text labels look like regarding this
also is this a 1v1 game

show the explorer

NEVERMIND YOU DID GIVE ME A MOMENT