Why is GoodSignal not working in my scenario?

So I’m trying to use GoodSignal across modules in my game, but for some reason it doesn’t detect the :Connect signal when I try to use it in a script. The thing is that I have this module “DataManager” where I implement the :Fire function within a class method, but when I require that module in the server script and try to bind the event to a function it’s like if that part of the code didn’t even exist. welp

DataHandler (ServerScriptService)

local dataManager = require(game.ServerScriptService.DataManager)
local function updateValue(data, leaderstats)
	leaderstats.Cash.Value = data.Cash
	leaderstats.Range.Value = math.floor(data.Range * 1e2) / 1e2
end
players.PlayerAdded:Connect(function(player)
	local playerData = dataManager.GetPlayerData(player)
	local leaderstats = Instance.new("Folder", player)
	local gunpowder = Instance.new("IntValue", leaderstats)
	local cash = Instance.new("IntValue", leaderstats)
	local range = Instance.new("NumberValue", leaderstats)
	leaderstats.Name = "leaderstats"
	gunpowder.Name = "Gunpowder"
	cash.Name = "Cash"
	range.Name = "Range"
	local connection = playerData.Changed:Connect(function()
		print(true)
	end) --This is where it should print 'true' but it doesn't
	cash.Value = playerData:Get("Cash")
	range.Value = playerData:Get("Range")
end)
players.PlayerRemoving:Connect(function(player)
	dataManager.GetPlayerData(player):Release()
end)
while task.wait(2) do
	dataManager.GetPlayerData(game.Players.FederalNando):Increase("Cash", 1)
	print("Done")
end

DataManager (ServerScriptService too)

local profileStore = require(script.ProfileService).GetProfileStore("PlayerData", {
	Cash = 0,
	Range = 0,
	GunpowderMultiplier = 1,
	CashMultiplier = 1,
	RangeMultiplier = 1,
	MaxHealth = 1,
	MaxSpeed = 10,
	MaxGunpowder = 10,
	OwnedSkins = {}
})
local dataManager = {}
local profiles = {}
dataManager.__index = dataManager
function dataManager.GetPlayerData(player)
	local playerData = {
		Changed = goodSignal.new()
	}
	local existingProfile = profiles[player]
	if existingProfile then
		playerData.Profile = existingProfile
	else
		local userId = player.UserId
		local profile = profileStore:LoadProfileAsync(`Player_{userId}`)
		if profile then
			profile:AddUserId(userId)
			profile:Reconcile()
			profile:ListenToRelease(function()
				profiles[player] = nil
				player:Kick("Same account has been launched from another device. Join back if you wanna play from this one.")
			end)
			if player:IsDescendantOf(game.Players) then
				profiles[player] = profile
				playerData.Profile = profile
			else
				profile:Release()
			end
		else
			player:Kick("Unable to load your data. Join back to try again.")
		end
	end
	return setmetatable(playerData, dataManager)
end
function dataManager:Get(index)
	return self.Profile.Data[index]
end
function dataManager:Set(index, value)
	self.Profile.Data[index] = value
	self.Changed:Fire(index, value)
end
function dataManager:Increase(index, increment)
	local value = self.Profile.Data[index] + increment or increment
	self.Profile.Data[index] = value
	self.Changed:Fire(index, value) --This is where I fire the signal
end
function dataManager:Decrease(index, decrement)
	local value = self.Profile.Data[index] - decrement or -decrement
	self.Profile.Data[index] = value
	self.Changed:Fire(index, value)
end
function dataManager:Release()
	if self.Profile then
		self.Profile:Release()
	end
	self.Changed:DisconnectAll()
end
return dataManager

Also I’m not that good with roblox OOP. Maybe it’s somehow related…? idk, someone help :sob:

Code looks alright but it seems to be the testing code that is not

You are creating a new signal object everytime using get player data.

You should store the signal data in a dictionary in a module script.

This is the first thing I saw there might be something else.

1 Like

Well, that was the issue :moyai:. Thanks a lot dude, saved my whole existence.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.