I have a problem creating a "2x coins" gamepass

Hello ! Here is my problem: a friend helped me make a script of X2 coins with a gamepass except that it gives the X2 coins even without the gamepass. Here is the script:

game.ReplicatedStorage.Events.dest.OnServerEvent:Connect(function(plr, tar)
    tar:Destroy()
end)
--Drop Manager
local debris = game:GetService("Debris")

function randomN(num1,num2)
    return math.random(num1*1000,num2*1000)/1000
end
function Drop(Tar)
    local dropValue = Tar:FindFirstChild("Drop")
    if dropValue then
        if dropValue.Value > 0 then

        end
    end
end

game.ReplicatedStorage.Events.drop.OnServerEvent:connect(function(plr, Tar, despawnTime)
    local dropValue = Tar:FindFirstChild("Drop")
    if dropValue then
        if dropValue.Value > 2 then
            local Give = plr:WaitForChild("leaderstats").Coins -- Change to thing what you want to give when player mined something.
local gamepassId = 7226231
           if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(plr.UserId,gamepassId) then
 Give.Value = Give.Value + dropValue.Value*2
else
Give.Value = Give.Value + dropValue.Value*2
        end
     end
    end
end)

--Damage
function damg(plr, Dur, dmg)
    Dur.Value = Dur.Value - dmg
end

game.ReplicatedStorage.Events.damage.OnServerEvent:connect(damg)````
4 Likes
Give.Value = Give.Value + dropValue.Value.gamepassId*2

What??? Just use

Give.Value = Give.Value + dropValue.Value
3 Likes
if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(plr.UserId,gamepassId) then
 Give.Value = Give.Value + dropValue.Value*2
else
Give.Value = Give.Value + dropValue.Value

replace

1 Like

I made a error , gamepassid is not in the script.

people here is my problem in the script

game.ReplicatedStorage.Events.dest.OnServerEvent:Connect(function(plr, tar)
    tar:Destroy()
end)
--Drop Manager
local debris = game:GetService("Debris")

function randomN(num1,num2)
    return math.random(num1*1000,num2*1000)/1000
end
function Drop(Tar)
    local dropValue = Tar:FindFirstChild("Drop")
    if dropValue then
        if dropValue.Value > 0 then

        end
    end
end

game.ReplicatedStorage.Events.drop.OnServerEvent:connect(function(plr, Tar, despawnTime)
    local dropValue = Tar:FindFirstChild("Drop")
    if dropValue then
        if dropValue.Value > 2 then
            local Give = plr:WaitForChild("leaderstats").Coins -- Change to thing what you want to give when player mined something.
local gamepassId = 7226231
           if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(plr.UserId,gamepassId) then
 Give.Value = Give.Value + dropValue.Value*2
else
Give.Value = Give.Value + dropValue.Value
        end
     end
    end
end)

--Damage
function damg(plr, Dur, dmg)
    Dur.Value = Dur.Value - dmg
end

game.ReplicatedStorage.Events.damage.OnServerEvent:connect(damg)````

Where it says:

if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(.UserId,gamepassId) then
    Give.Value = Give.Value + dropValue.Value*2
else
    Give.Value = Give.Value + dropValue.Value*2  < Fix here

The second one should not have a *2 at the end

hello , i have test but is same :c

I’ll try to help you about a bit, but first I want to point out this;


game.ReplicatedStorage.Events.dest.OnServerEvent:Connect(function(plr, tar)
    tar:Destroy()
end)

This opens up a gateway which would let exploiters delete any object in your game without any hassle! I don’t have the context of what this is used for, but you should really have this handled server-side instead.


function Drop(Tar)
    local dropValue = Tar:FindFirstChild("Drop")
    if dropValue then
        if dropValue.Value > 0 then
        end
    end
end

This code serves no purpose whatsoever. It doesn’t return anything or change anything. so you should probably just scrap it unless you had some other plans.

And, for checking if you want to see if the player owns the gamepass or not, you should have the game create a BoolValue under the player named “Owns(gamepass name)”, and perform the UserOwnsGamePassAsync only once, to set this value. Then, when you need to find out if they own the gamepass later when determining if they get the 2x coins or not, just have the script refer to that BoolValue.

This will make your code a lot more efficient. One more thing that, didn’t make much sense, was when you tried getting “dropValue.Value.gamepassId” on Line 29. You might want to change it to just “Give.Value = Give.Value + dropValue.Value”

hello , im delete the script ??

If it’s not doing anything, yeah. No point in having a function that you never touch, that doesn’t do anything.

hello I tested everything and it always does the same thing but I’m going to try to remove the exploiter thing