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

How do i make a x2 coins gamepass with this code?

Asked by 3 years ago

So i have been wondering how to make a x2 coins gamepass and i need help, can i integrate a x2 coins gamepass with this code?

waittime = 13 -- Time Between each hit
amnt = 10 --how much you get for it
function onTouched(part)
    local h = part.Parent:findFirstChild("Humanoid")
    if (h~=nil) then
        local thisplr = game.Players:findFirstChild(h.Parent.Name)
        if (thisplr~=nil) then
            local stats = thisplr:findFirstChild("leaderstats")
            if (stats~=nil) then
                local score = stats:findFirstChild("Coins")
                if (score~=nil) then
                    score.Value = score.Value + amnt
                end
            end
        end

        script.Parent.Transparency = 1
        script.Parent.CanCollide = false
        script.Disabled = true
        wait(waittime)
        script.Parent.Transparency = 0
        script.Parent.CanCollide = true
        script.Disabled = false     


    end
end

script.Parent.Touched:connect(onTouched)
0
Line 19 tho Ziffixture 6913 — 3y
0
I would use a debounce instead of doing script.Disabled just in case it causes any problems. Other than that i think it would work fine. Also, I would make a base amount to give the player and then do an if statement to check if the player had the gamepass and if they do, amnt = amnt * 2, this could make your code easier to manage. YT_GamingDan 10 — 3y
0
You must use a debounce. Disabling the Script will require second-hand reactivation. You can also just set up a Ternary using MarketplaceService's 'UserOwnsGamePassAsync' Boolean to bias amount or amount * 2. Ziffixture 6913 — 3y
0
i have no idea how to script, my friend came up with this and he cant help me with the x2 coins game pass thing so i came here for some help coolperson21216 4 — 3y

1 answer

Log in to vote
0
Answered by
174gb 290 Moderation Voter
3 years ago
Edited 3 years ago

I edited your code a little bit and this should work, all you need to do is get your gamepass id and change it to 'GamePassId'

local MPS = game:GetService("MarketplaceService")
local Players = game:GetService("Players")

local GamePassId = 15200883 -- your gamepass id here
local RespawnTime = 13
local Reward = 10
local Collected = false

function Touch(object)
    if object.Parent:FindFirstChild("Humanoid") then
        if Players:GetPlayerFromCharacter(object.Parent) then
            local Player = Players:GetPlayerFromCharacter(object.Parent)
            local leaderstats = Player:FindFirstChild("leaderstats")
            local Coins = leaderstats:FindFirstChild("Coins")
            if leaderstats ~= nil and Coins ~= nil then
                if not Collected then
                    Collected = true
                    if not MPS:UserOwnsGamePassAsync(Player.UserId, GamePassId) then
                        Coins.Value += Reward
                    else
                        Coins.Value += Reward *2
                    end
                    script.Parent.Transparency = 1
                    script.Parent.CanCollide = false
                    wait(RespawnTime)
                    script.Parent.Transparency = 0
                    script.Parent.CanCollide = true
                    Collected = false
                end
            end
        end
    end
end

script.Parent.Touched:connect(Touch)
0
Thanks for the help,i have been struggling so much to make one! coolperson21216 4 — 3y
Ad

Answer this question