Different Approaches for Double Coins gamepass

Hello,

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?

That will cause a recursive loop which will crash the server, because when you add the difference, it will trigger the event again.

Or a third option, just structure your code well enough that you don’t have to change a bunch of scripts for a small change like this.

If you could provide your code, I can help you.

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?

2 Likes

Yeah, that’s a good idea. Have a module that handles player data so you can modify it whenever.

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.