Help on updating gui label scores to all players on the game server

making a ‘csgo/valorant’ gamestyle

and i’ve got a problem where the gui text labels aren’t updating correctly

  1. if a team wins the first round the label won’t update to them but will update correctly to the loser team (after that round everything works fine)

  2. if someone is on a spectating team which is different from the teams competing the score labels wont update to them if they won’t reset or respawn

  • using a normal script in serverscriptservice
  • using a localscript inside the ScreenGUI
1 Like

Could you provide some code or files that I could look at?

this is the serverscripservice one, if you need the LocalScript on the StarterGui too LMK.

– Configuration
local team1Name = “ANTGS” – Name of Team1
local team2Name = “DARKNESS” – Name of Team2
local maxPlayersPerTeam = 3 – Maximum number of players per team
local respawnDelay = 5 – Delay before respawn in seconds

– Dictionary to store players’ death status and team death status
local playerDeadStatus = {}
local teamScores = {
[team1Name] = 0, – Initial score for Team1
[team2Name] = 0 – Initial score for Team2
}

– Remote event to update the team’s score label on clients
local updateScoreEvent = Instance.new(“RemoteEvent”)
updateScoreEvent.Name = “UpdateScoreLabel”
updateScoreEvent.Parent = game.ReplicatedStorage

– Sound to play at the end of the round
local roundEndSound = Instance.new(“Sound”)
roundEndSound.SoundId = “rbxassetid://5350726270” – Replace with the SoundId of your desired sound
roundEndSound.Parent = game.Workspace

– Function to check if all players in a team are dead
local function IsTeamDead(teamName)
local team = game.Teams:FindFirstChild(teamName)
if not team then
return false
end

local players = team:GetPlayers()
for _, player in ipairs(players) do
	if not playerDeadStatus[player] then
		return false
	end
end

return true

end

– Function to respawn all players in a team
local function RespawnTeam(teamName)
local team = game.Teams:FindFirstChild(teamName)
if not team then
return
end

local players = team:GetPlayers()
for _, player in ipairs(players) do
	player:LoadCharacter()
	playerDeadStatus[player] = nil
end

-- Update the team's score label on all clients
for _, player in ipairs(game.Players:GetPlayers()) do
	updateScoreEvent:FireClient(player, teamName, teamScores[teamName])
end

-- Play the round end sound
roundEndSound:Play()

end

– Function to handle player death
local function OnPlayerDied(character)
local player = game.Players:GetPlayerFromCharacter(character)
if not player then
return
end

playerDeadStatus[player] = true

local team = player.Team
if team and (team.Name == team1Name or team.Name == team2Name) then
	local players = team:GetPlayers()

	local teamDead = true
	for _, p in ipairs(players) do
		if not playerDeadStatus[p] then
			teamDead = false
			break
		end
	end

	if teamDead then
		local opposingTeamName = team.Name == team1Name and team2Name or team1Name
		teamScores[opposingTeamName] = teamScores[opposingTeamName] + 1
		RespawnTeam(opposingTeamName)
	end

	-- Update the team's score label on all clients
	for _, player in ipairs(game.Players:GetPlayers()) do
		updateScoreEvent:FireClient(player, team.Name, teamScores[team.Name])
	end

	local screenGui = game.StarterGui:FindFirstChild("ScreenGui2")
	if screenGui then
		local team1Label = screenGui:FindFirstChild("Team1Label")
		if team1Label then
			team1Label.Text = team1Name .. ": " .. teamScores[team1Name]
		end

		local team2Label = screenGui:FindFirstChild("Team2Label")
		if team2Label then
			team2Label.Text = team2Name .. ": " .. teamScores[team2Name]
		end
	end
end

if IsTeamDead(team1Name) then
	RespawnTeam(team1Name)
elseif IsTeamDead(team2Name) then
	RespawnTeam(team2Name)
end

end

– Connect the player death event
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
character:WaitForChild(“Humanoid”).Died:Connect(function()
wait(respawnDelay) – Delay before respawn
OnPlayerDied(character)
end)
end)
end)

– Function to update the team’s score label on all clients
local function UpdateScoreLabels()
for _, player in ipairs(game.Players:GetPlayers()) do
updateScoreEvent:FireClient(player, team1Name, teamScores[team1Name])
updateScoreEvent:FireClient(player, team2Name, teamScores[team2Name])
end
end

– Update the team’s score labels when the game starts
UpdateScoreLabels()

– Update the team’s score labels when a player joins or leaves the game
game.Players.PlayerAdded:Connect(UpdateScoreLabels)
game.Players.PlayerRemoving:Connect(UpdateScoreLabels)

From this reply I couldn’t see the codes well do eithers got discord?

yes d ☆#0001 just copy and paste it

Doesn’t seem to be workings add me then Vuzionix#8341