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

How can i make a x2 Coins event? (where you get double coins)

Asked by 3 years ago
Edited 3 years ago

I have no idea how to make this, can someone help me and explain this to me

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

local GamePassId = 10211208 -- 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
Do you mean like when you pick up a coin it give you a double when event? The_Saver31 260 — 3y
0
yes coolperson21216 4 — 3y
0
i can do it The_Saver31 260 — 3y
0
wait 1 hour The_Saver31 260 — 3y
View all comments (5 more)
0
i still have something to do The_Saver31 260 — 3y
0
ok, thanks! coolperson21216 4 — 3y
0
no problem :D The_Saver31 260 — 3y
0
There you are :D, Sorry if its not working! Comment on it if its not working!!! The_Saver31 260 — 3y
0
Use :Connect instead of :connect, as it is deprecated RazzyPlayz 497 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago

Hello.

The issue that you are facing is that in the script you are checking if the leaderstats do not exist, and same with the coins. Since you have this line in the code, anything that's below that line of code will not run as long as you have the leaderstats existing.

With that said, also make sure you have the correct leaderstats script to utilise this script. In your case, you can use something as simple as this for the leaderstats:

local Players = game:GetService("Players")

local function SetupLeaderstats(Player)
    local leaderstats = Instance.new("Folder")
    leaderstats.Name = "leaderstats"
    leaderstats.Parent = Player

    local Coins = Instance.new("IntValue")
    Coins.Name = "Coins"
    Coins.Parent = leaderstats
end

Players.PlayerAdded:Connect(SetupLeaderstats)

Afterwards, you can then update your code to the following edited code to make the Double Coins gamepass function correctly, and doubling the amount of coins that you would obtain without a gamepass (10) and double it to 20 if you have the gamepass.

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

local GamePassId = 10211208
local RespawnTime = 13

local Reward = 10
local Collected = false

local function CoinTouched(ObjectCollided)
    if (ObjectCollided.Parent:FindFirstChild("Humanoid")) then
    local Player = Players:GetPlayerFromCharacter(ObjectCollided.Parent)
        if (Player) then
            local leaderstats = Player:FindFirstChild("leaderstats")
            local Coins = leaderstats:FindFirstChild("Coins")
            if not (Collected) then
                Collected = true
                if not (MarketPlaceService: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

script.Parent.Touched:Connect(CoinTouched)

Hope this helps, please comment down any issues you have with the script.

0
thanks for the help, but i want the x2 gamepass and the x2 coin event into it (also the doube coin gamepass alr works with me just fine!) coolperson21216 4 — 3y
0
Do you want the x2 Coin Event to apply for all players with no gamepass? x2 gamepass owners earn double from the event? RazzyPlayz 497 — 3y
0
yes coolperson21216 4 — 3y
0
Ah, then it's just as easy as to change the reward number from 10 to 20! This will automatically make the coin give 20 by default, and 40 to the people who own a gamepass. RazzyPlayz 497 — 3y
View all comments (2 more)
0
ok.. thats easy.. wow thx coolperson21216 4 — 3y
0
Glad it worked! Make sure to accept the answer so people know it's answered RazzyPlayz 497 — 3y
Ad

Answer this question