I would like to make a double coins gamepass, but my issue is that I have many different ways to gain coins in my game in many different different scripts. Is there a way for me to use GetPropertyChangedSignal to make it so that whenever a user’s coins value gets changed, it can find the difference and add the difference? Or am I stuck by just using if else ladders in all of my scripts?
It is hard for me to find all occurences of me adding coins to the user, especially since I have things such as a group chest where I chest if the user’s furthest zone is 1, 2, 3, 4, etc and add coins from there respectively. Are you saying I should maybe have a module function called “Add Coins” or smthn and just call that function for the user potentially?
I mean you could try. It wouldn’t be the best method and you should try to adapt your game to where you don’t use :GetPropertyChangedSignal()
If you had too, Here is an Example Of what you could do with :GetPropertyChangedSignal…
local Gamepass = nil --replace with gamepass ID
game.Players.PlayerAdded:Connect(function(player)
if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId, Gamepass) then
local CoinsValue = nil --Replace with the Int / Number value for Coins. Make sure your data is loaded and it has its true value by this time.
local OldValue = CoinsValue.Value
local LastChange = nil
CoinsValue:GetPropertyChangedSignal("Value"):Connect(function()
if LastChange == nil and CoinsValue.Value > OldValue or CoinsValue.Value > OldValue and CoinsValue.Value - OldValue ~= LastChange then
LastChange = CoinsValue.Value - OldValue
OldValue = CoinsValue.Value
CoinsValue.Value += LastChange
elseif LastChange ~= nil and CoinsValue.Value - OldValue == LastChange then
OldValue = CoinsValue.Value
LastChange = nil
else
OldValue = CoinsValue.Value
end
end)
end
end)
I think the above could work. Would I recommend it? No. If you could make a module that would most likely be way better then this could ever be.