Basically, in another script, each time a player dies on a team, the death value of the team is increased by 1. What this script is doing is breaking the rounds's for loop as soon as a team's death value equals to the number of players in that team. This will define the "WinningTeam" variable, either Red OR Blue. Everything works, except that the only way the for loop is broken is if a player leaves the game. I have no clue why, but maybe one of you guys can determine why the script is doing this. My script is below. Thanks for your time!;)
Round Script:
01 | local RedDeaths = game.Workspace.Config.RedDeaths |
02 | local BlueDeaths = game.Workspace.Config.BlueDeaths |
03 | local WinningTeam |
04 |
05 | for i = 150 , 1 ,- 1 do |
06 |
07 | if BlueDeaths.Value = = #game.Teams.Blue:GetPlayers() then |
08 | WinningTeam = game.Teams.Red |
09 | break |
10 | end |
11 | if RedDeaths.Value = = #game.Teams.Red:GetPlayers() then |
12 | WinningTeam = game.Teams.Blue |
13 | break |
14 | end |
15 |
Team Death Value Script:
01 | Player = game.Players.LocalPlayer |
02 | local RedTeamDeaths = game.Workspace.Config.RedDeaths |
03 | local BlueTeamDeaths = game.Workspace.Config.BlueDeaths |
04 | humanoid = Player.Character:findFirstChild( "Humanoid" ) |
05 |
06 | function DisableBackpack() |
07 | local StarterGui = game:GetService( 'StarterGui' ) |
08 | StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, false ) |
09 | end |
10 |
11 | function DiedX_X() |
12 | if Player.Team = = game.Teams.Red then |
13 | print ( '1 red team player has died!' ) |
14 | RedTeamDeaths.Value = RedTeamDeaths.Value + 1 |
15 | end |
With FilteringEnabled, you cannot directly modify values on the server from the client.
I suggest you handle the deaths on the server.
This can be done using a PlayerAdded
event, a CharacterAdded
event, and a Died
event.
01 | --Declarations |
02 | local config = workspace.Config; |
03 | local RedDeaths,BlueDeaths,WinningTeam = config.RedDeaths,config.BlueDeaths; |
04 |
05 | --Death handler |
06 | game.Players.PlayerAdded:Connect( function (plr) |
07 | plr.CharacterAdded:Connect( function (char) |
08 | local hum = char:WaitForChild( "Humanoid" ); |
09 | hum.Died:Connect( function () |
10 | local val; |
11 | if plr.Team = = game.Teams.Red then |
12 | val = RedDeaths; |
13 | elseif plr.Team = = game.Teams.Blue then |
14 | val = BlueDeaths; |
15 | end |