Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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:

01local ReplicatedStorage = game:GetService("ReplicatedStorage")
02local Players = game:GetService("Players")
03local Teams = game:GetService("Teams")
04local newGame = ReplicatedStorage.Timers.NewGame
05 
06 
07module = {}
08 
09Players.PlayerRemoving:Connect(function(player)
10    for i, v in pairs(module) do
11        if v == player then
12            table.remove(module, i)
13        end
14    end
15end)
View all 30 lines...

red team module:

01local ReplicatedStorage = game:GetService("ReplicatedStorage")
02local Players = game:GetService("Players")
03local Teams = game:GetService("Teams")
04local newGame = ReplicatedStorage.Timers.NewGame
05 
06module = {}
07 
08Players.PlayerRemoving:Connect(function(player)
09    for i, v in pairs(module) do
10        if v == player then
11            table.remove(module, i)
12        end
13    end
14end)
15 
View all 28 lines...

button:

01local ReplicatedStorage = game:GetService("ReplicatedStorage")
02local ServerScriptService = game:GetService("ServerScriptService")
03local Players = game:GetService("Players")
04local Teams = game:GetService("Teams")
05local bank = script.Parent
06local bankRequest = ReplicatedStorage.ItemEvents.BankRequested
07local bankEvent = ReplicatedStorage.ItemEvents.BankTouched
08local blueTeam = require(ServerScriptService.BlueTeamModule)
09local redTeam = require(ServerScriptService.RedTeamModule)
10local blueTimer = ReplicatedStorage.Timers.BlueTimer
11local redTimer = ReplicatedStorage.Timers.RedTimer
12local banked
13local newGame = ReplicatedStorage.Timers.NewGame
14 
15local blueBanked = {}
View all 43 lines...

1 answer

Log in to vote
0
Answered by 4 years ago

Ok, so I now realize that modulescripts are the wrong tool for what I'm trying to do (just store a value that all other scripts can access) and that _G is a MUCH better solution. I'm storing the tables with the team members in global variables rather than a module.

Ad

Answer this question