Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

I am trying to make it so if somebody owns a certain gamepass that they get a 2x leaderstats boost?

Asked by 4 years ago

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

local GamepassID = 10409558
local ClickAmount = 1

local debounce = false
script.Parent.ClickDetector.MouseClick:Connect(function(player)
    if debounce == false then
    debounce = true
    local PlayerClicks = player.leaderstats.Clicks
    PlayerClicks.Value = PlayerClicks.Value  + ClickAmount
    game.Players.PlayerAdded:Connect(function(player)

        if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId, GamepassID) then
        PlayerClicks.Value = PlayerClicks + ClickAmount + 1
    end
end)


    wait(0.1)
    debounce = false
        end
end)








2 answers

Log in to vote
1
Answered by 4 years ago
Edited 4 years ago

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.

PlayerClicks.Value = PlayerClicks.Value + (ClickAmount * 2)
0
Works thanks Killerbot712 47 — 4y
Ad
Log in to vote
-1
Answered by 4 years ago

On line 13 try PlayerClicks.Value = PlayerClicks + ClickAmount + 2

Answer this question