Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
0

Double Coins Gamepass Wrong Values?

Asked by 8 months ago

Hello! In my game, I am trying to make a double coins gamepass. Each round, the player should earn 5 coins (so double coins would give them 10). The gamepass works, and 10 coins are rewarded. However, if you don't own the gamepass, you sometimes receive 5 coins like you are supposed to and other times you receive 15 coins.

  • No errors are given
  • This has only been tested in singleplayer
  • The script only happens once, because the Wins go up only 1. (This is the purpose of having some of the variables) -

Thanks to anyone who attempts to help!

script.Parent.Touched:Connect(function(p)
    local char = p.Parent.Name
    local player = game.Players:FindFirstChild(char)
    local numWins = player.leaderstats.Wins.Value
    local numCoins = player.leaderstats.Coins.Value
    local CoinsEarned = 5

    player.Character.HumanoidRootPart.CFrame = game.Workspace.LOBBYTELE.CFrame

    wait(2)
    local service = game:GetService("MarketplaceService")
    if service:UserOwnsGamePassAsync(player.userId,8519306) == true then
        CoinsEarned = 10
    end
    player.leaderstats.Coins.Value = numCoins + CoinsEarned
    player.leaderstats.Wins.Value = numWins + 1
end)

1 answer

Log in to vote
2
Answered by
Ziffixture 5789 Moderation Voter Community Moderator
8 months ago
Edited 8 months ago

This is just a cleanup

local MpS = game:GetService ("MarketplaceService")
local Gamepass = 8519306

local Part = script.Parent

local function PlayerWonAction(Target)
    if not (Target) then return end
    local Player = game.Players:GetPlayerFromCharacter(Target.Parent)
    if (Player and Player.Character) then
        local Leaderstats = Player:FindFirstChild("leaderstats")
        if (Leaderstats and Leaderstats.Coins and Leaderstats.Wins) then
            local CoinsEarned = MpS:UserOwnsGamepassAsync(Player.UserId, Gamepass) and 10 or 5
            Leaderstats.Coins.Value = (Leaderstats.Coins.Value + CoinsEarned)
            Leaderstats.Wins.Value = (Leaderstats.Wins.Value + 1)
        end
        Character:SetPrimaryPartCFrame(workspace.LOBBYTELE.CFrame)
    end
end

Part.Touched:Connect(PlayerWonAction)
0
Thank you! This definitely easier to read than what I had lol :) XDgirl909090 150 — 8mo
Ad

Answer this question