You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? Keep it simple and clear!
what the gui to be for each player
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
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.
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
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?
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
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;
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 ?
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
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