and i’ve got a problem where the gui text labels aren’t updating correctly
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) but the scores on the first round winners will be delayed by the point that they didnt get the first round
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 **
I have discord but i prefer you do it here instead, please could you provide me your serverside code and client side codes so i can help you here, Thanks!
serverside code:
– 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)
client side code:
– Client-side code
– Function to update the score label on the client
local function UpdateScoreLabel(teamName, score)
local screenGui = game.Players.LocalPlayer.PlayerGui:WaitForChild(“ScreenGui2”)
local teamLabel = screenGui:FindFirstChild(teamName … “Label”)
if teamLabel then
teamLabel.Text = teamName … ": " … score
end
end
– Remote event to update the score label on the client
local updateScoreEvent = game.ReplicatedStorage:WaitForChild(“UpdateScoreLabel”)
– Listen for the event and update the score label when received
On the client side you only seem to be updating the code once, maybe you should also do a characterremoving to check if the player has died, on the other message i have to admit, it does look like chatpgt generated it lol.