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.
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)
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)