Hi, i made a script that gives people a 2x boost if they own a certain gamepass I own the gamepass but i still only get + 1 leaderstats
Here is my code
01 | local GamepassID = 10409558 |
02 | local ClickAmount = 1 |
03 |
04 | local debounce = false |
05 | script.Parent.ClickDetector.MouseClick:Connect( function (player) |
06 | if debounce = = false then |
07 | debounce = true |
08 | local PlayerClicks = player.leaderstats.Clicks |
09 | PlayerClicks.Value = PlayerClicks.Value + ClickAmount |
10 | game.Players.PlayerAdded:Connect( function (player) |
11 |
12 | if game:GetService( "MarketplaceService" ):UserOwnsGamePassAsync(player.UserId, GamepassID) then |
13 | PlayerClicks.Value = PlayerClicks + ClickAmount + 1 |
14 | end |
15 | end ) |
You have two options here, the good way and the not good way, but works way.
The good way, move the PlayerAdded event outside of your MouseClick event and create a dictionary to cache whether they own the gamepass or not so your script won't have to yield every time it calls, UserOwnsGamePassAync. Then in your MouseClick event check if the player is a valid key in the dictionary and if they are, grant them their bonus.
The not good way, but works way is to remove the PlayerAdded event completely and inside the MouseClick event just check if they own the gamepass and grant them the bonus.
Also to double the amount of click's it will give you, you have to multiply the number by two.
1 | PlayerClicks.Value = PlayerClicks.Value + (ClickAmount * 2 ) |
On line 13 try PlayerClicks.Value = PlayerClicks + ClickAmount + 2