Hello!
I'm having difficulties converting my deathmatch script into a team deathmatch, where the goal is for the team to reach the Max Score, before the other player. I've included my full script below, and Line 108 on, is where I really need the help, I've never messed with the "Teams" stuff prior. Up until that point in the script, it functions properly, but once I get to the winner part, I'm a bit off in the woods.
I've set up two IntValues to represent each team's score, which does update, per the Death Script I've included below.
Output error: 01:40:27.597 - ServerScriptService.MainScriptRounds:127: attempt to call a boolean value.
This error pops up after one side has reached the max score, the countdown timer freezes, and the game does not end. I'm not sure why I can't call the boolValue/Leaderstats? I was able to when it was a single player game. Is there a different line of code needed when it becomes a team game?
Main Team Deathmatch Script below:
local replicatedstorage = game:GetService('ReplicatedStorage') local status = replicatedstorage:WaitForChild('InfoValue') local mapstorage = game.workspace:WaitForChild('mapStorage') local StarterGui = game:GetService('StarterGui') local serversettings = replicatedstorage.ServerSettings local silverscore = serversettings.SilverScore --IntValue that should change when the team scores. local goldscore = serversettings.GoldScore --IntValue that should change when the team scores. local modulesilverscore = require(game.ServerStorage.SilverScoreScript) local modulegoldscore = require(game.ServerStorage.GoldScoreScript) --local ScoreDisplay = game:GetService('StarterGui').Score.Frame while true do if game.Players.NumPlayers < 2 then status.Value = 'There needs to be 2 or more players to begin!' repeat wait(2) until game.Players.NumPlayers >= 2 end --Intermission for i = 20,0,-1 do --First number is the length in seconds of the Intermission status.Value = 'Intermission '..i wait(1) end _G.gameplayers = {} for i, v in pairs(game.Players:GetPlayers()) do if v then table.insert(_G.gameplayers, v.Name) end end -- Random Map selection & Spawns local h = Instance.new("Hint", game.Workspace) local mapsinserverstorage = game:GetService('ServerStorage').Maps:GetChildren() local chosenmap = mapsinserverstorage[math.random(1,#mapsinserverstorage)] chosenmap:Clone().Parent = mapstorage h.Text = "Be the last to survive!" status.Value = 'Now Loading: ' .. chosenmap.Name .. '! Get ready to be teleported to the map!' wait(9) h:Destroy() local spawns = chosenmap:WaitForChild('Spawns'):GetChildren() for _, player in pairs(game.Players:GetPlayers()) do if player and #spawns > 0 then local torso = player.Character:WaitForChild('Torso') local allspawns = math.random(1, #spawns) local randomspawn = spawns[allspawns] if randomspawn and torso then table.remove(spawns, allspawns) torso.CFrame = CFrame.new(randomspawn.Position + Vector3.new(0,2,0)) --Grant team-specific weapons. local tool1 = game.ReplicatedStorage.AK local team1 = BrickColor.new("Pearl") if player.TeamColor == team1 then tool1:Clone().Parent = player.Backpack end local tool2 = game.ReplicatedStorage.IceTouch local team2 = BrickColor.new("Gold") if player.TeamColor == team2 then tool2:Clone().Parent = player.Backpack end print("Removing ForceField1") local players = game.Players:GetChildren() for i, plr in ipairs(players) do plr.InSafezone.Value = false end print("Removing ForceField2") end end end wait(1) -- Round information for i = 90, 0, -1 do -- first number is the amount of time the Round is, the 0 is when it ends, the -1 is how fast the time goes. if i == 0 then status.Value = 'Time Up! Round Over!' break end wait(1) --Here is where I've really messed up the script. --local team1 = BrickColor.new("Pearl"):GetPlayers() --local team2 = BrickColor.new("Gold"):GetPlayers() local maxscore = 2 local team1 = game.Teams.Silver local team2 = game.Teams.Gold if silverscore.Value == maxscore then for players in team1.TeamColor == team1.TeamColor do status.Value = 'Team 1 is the winner!' game.Players.leaderstats.Coins.Value = game.Players.leaderstats.Coins.Value + 5 game.Players.leaderstats.Experience.Value = game.Players.leaderstats.Experience.Value + 10 game.Players.leaderstats.Wins.Value = game.Players.leaderstats.Wins.Value + 1 end elseif goldscore.Value == maxscore then for players in team2.TeamColor == team2.TeamColor do status.Value = 'Team 2 is the winner!' game.Players.leaderstats.Coins.Value = game.Players.leaderstats.Coins.Value + 5 game.Players.leaderstats.Experience.Value = game.Players.leaderstats.Experience.Value + 10 game.Players.leaderstats.Wins.Value = game.Players.leaderstats.Wins.Value + 1 end break else status.Value = i..' seconds remaining!' end end mapstorage:ClearAllChildren() wait(3) end
Death Script:
local t1 = game.Teams.Silvers local t2 = game.Teams.Golds local replicatedstorage = game:GetService('ReplicatedStorage') local serversettings = replicatedstorage.ServerSettings --Team IntValues inside a ScreenGui that should change when a player on a team scores a point. local silverscore = serversettings.SilverScore local goldscore = serversettings.GoldScore game.Players.PlayerAdded:connect(function(player) player.CharacterAdded:connect(function(char) local hum = char:WaitForChild('Humanoid') hum.Died:connect(function() local tag = hum:FindFirstChild('creator') if tag ~= nil then if tag.Value ~= nil then local leaderstats = tag.Value:FindFirstChild('leaderstats') if leaderstats ~= nil then leaderstats.Coins.Value = leaderstats.Coins.Value + player.leaderstats.Level.Value * 2 leaderstats.Experience.Value = leaderstats.Experience.Value + player.leaderstats.Level.Value * 20 leaderstats.Kills.Value = leaderstats.Kills.Value + 1 end end end if player.TeamColor == t1.TeamColor then silverscore.Value = silverscore.Value +1 elseif player.TeamColor == t2.TeamColor then goldcore.Value = goldscore.Value +1 end end) end) end)
Thank you!!
for line 127 it should be different format:
for i,plr in pairs(players) do --loop through each player if plr.Team == teamname then --code end end
or just use Team:GetPlayers() : link
for i,plr in pairs(Team:GetPlayers()) do --code end
hope this helped