Greetings,
I am currently working with a Module Script in my game that is responsible for managing various tasks. However, I’ve encountered an issue where the script operates globally for all players, rather than executing individually for each player.
So far, i have attempted to put the “TaskGroups” table inside the “checkGroups” function.
Task Module:
local playerService = game:GetService("Players")
local dataMod = require(script.Parent.Data)
local spawnParts = workspace.SpawnParts
local TasksMod = {}
local function getWins(winsNum)
for _, winsPart in pairs(spawnParts:GetChildren()) do
if winsPart.Wins.Value == winsNum then
return winsPart
end
end
end
local TaskGroups = {
checkPlayerInGroup = false;
checkPlayerTime = false;
checkPlayerWins = false;
}
TasksMod.checkPlayerInGroup = function(player)
local groupId = 34325147
if player:IsInGroup(groupId) then
TaskGroups.checkPlayerInGroup = true
end
end
TasksMod.checkPlayerTime = function(player)
local startTime = tick()
while true do
wait(1)
local currentTime = tick()
local timeInGame = currentTime - startTime
if timeInGame >= 20 then
TaskGroups.checkPlayerTime = true
break
end
end
end
TasksMod.checkPlayerWins = function(player)
local winsNum = dataMod.get(player, "Wins")
if winsNum == 1 then
TaskGroups.checkPlayerWins = true
end
end
local function checkGroups(player)
TasksMod.checkPlayerInGroup(player)
TasksMod.checkPlayerWins(player)
coroutine.wrap(TasksMod.checkPlayerTime)(player)
local allTrue = true
for _, groupValue in pairs(TaskGroups) do
if groupValue ~= true then
allTrue = false
break
end
end
local output = ""
for groupName, groupValue in pairs(TaskGroups) do
output = output .. "{" .. groupName .. " = " .. tostring(groupValue) .. "}, "
end
output = output .. "{AllTrue = " .. tostring(allTrue) .. "}"
print(output)
return allTrue
end
TasksMod.getOutput = function(player)
return checkGroups(player)
end
playerService.PlayerAdded:Connect(checkGroups)
return TasksMod
Monetization Module:
The segment of the script that is crucial for invoking the output and conducting the checks.
local playerService = game:GetService("Players")
local dataService = game:GetService("DataStoreService")
local insertService = game:GetService("InsertService")
local marketService = game:GetService("MarketplaceService")
local spawnParts = workspace.SpawnParts
local dataMod = require(script.Parent.Data)
local tasksMod = require(script.Parent.Tasks)
local remoteEvent = game.ReplicatedStorage:WaitForChild("PromptPurchase")
local monetizationMod = {}
monetizationMod.getTaskOutput = function(player)
local output = tasksMod.getOutput(player)
print(output)
return output
end
local function getStage(stageNum)
for _, stagePart in pairs(spawnParts:GetChildren()) do
if stagePart.Stage.Value == stageNum then
return stagePart
end
end
end
monetizationMod.insertTool = function(player, assetId)
local asset = insertService:LoadAsset(assetId)
local tool = asset:FindFirstChildOfClass("Tool")
tool.Parent = player.Backpack
asset:Destroy()
end
remoteEvent.OnServerEvent:Connect(function(player)
local allTrue = monetizationMod.getTaskOutput(player)
if allTrue then
marketService:PromptPurchase(player, 0000000)
end
end)
Any assistance or suggestions provided would be highly appreciated. Thank you in advance for your time and help!