ModuleScript not returning correct value?
Asked by
4 years ago Edited 4 years ago
I'm making a game where there is a red team and a blue team, and each team has their own timer. There is a bank button where your coins that you collected on the map go into a separate leaderboard. All of that works, but I want the team's timer to go to 0 when everyone on the team has banked their coins. I am trying to do this by comparing the number of people on that team that clicked the button to the number of people on that team.
The modulescript that holds the members of the teams prints the people on the team correctly when the game starts, but when you click on the button, it lists an empty table.
blue team module:
01 | local ReplicatedStorage = game:GetService( "ReplicatedStorage" ) |
02 | local Players = game:GetService( "Players" ) |
03 | local Teams = game:GetService( "Teams" ) |
04 | local newGame = ReplicatedStorage.Timers.NewGame |
09 | Players.PlayerRemoving:Connect( function (player) |
10 | for i, v in pairs (module) do |
12 | table.remove(module, i) |
18 | newGame.Event:Connect( function () |
20 | for i, v in pairs (Players:GetPlayers()) do |
21 | if v.Team = = Teams.Blue then |
23 | table.insert(module, v) |
red team module:
01 | local ReplicatedStorage = game:GetService( "ReplicatedStorage" ) |
02 | local Players = game:GetService( "Players" ) |
03 | local Teams = game:GetService( "Teams" ) |
04 | local newGame = ReplicatedStorage.Timers.NewGame |
08 | Players.PlayerRemoving:Connect( function (player) |
09 | for i, v in pairs (module) do |
11 | table.remove(module, i) |
17 | newGame.Event:Connect( function () |
19 | for i, v in pairs (Players:GetPlayers()) do |
20 | if v.Team = = Teams.Red then |
22 | table.insert(module, v) |
button:
01 | local ReplicatedStorage = game:GetService( "ReplicatedStorage" ) |
02 | local ServerScriptService = game:GetService( "ServerScriptService" ) |
03 | local Players = game:GetService( "Players" ) |
04 | local Teams = game:GetService( "Teams" ) |
05 | local bank = script.Parent |
06 | local bankRequest = ReplicatedStorage.ItemEvents.BankRequested |
07 | local bankEvent = ReplicatedStorage.ItemEvents.BankTouched |
08 | local blueTeam = require(ServerScriptService.BlueTeamModule) |
09 | local redTeam = require(ServerScriptService.RedTeamModule) |
10 | local blueTimer = ReplicatedStorage.Timers.BlueTimer |
11 | local redTimer = ReplicatedStorage.Timers.RedTimer |
13 | local newGame = ReplicatedStorage.Timers.NewGame |
18 | bank.ClickDetector.MouseClick:Connect( function (player) |
20 | banked = bankRequest:InvokeClient(player) |
21 | if banked = = false then |
22 | bankEvent:FireClient(player) |
23 | player.leaderstats.Banked.Value = player.leaderstats.Coins.Value |
24 | player.leaderstats.Coins.Value = 0 |
25 | if player.Team = = Teams.Blue then |
26 | table.insert(blueBanked, player) |
29 | if #blueBanked = = #blueTeam then |
33 | elseif player.Team = = Teams.Red then |
34 | table.insert(redBanked, player) |
37 | if #redBanked = = #redTeam then |