hi, i want to check at the end of the game if the player has a gamepass (that doubles the coins that the player gets) and double the coins he gets if he owns the gamepass
if outcome == "time-up" then
for i, c in pairs(game.Players:GetPlayers()) do
if c:FindFirstChild("Contestant") then
local player = c
player.Tokens.Value = player.Tokens.Value + 20
player:FindFirstChild("leaderstats").Survivals.Value = player:FindFirstChild("leaderstats").Survivals.Value + 1
status.Value = "Time up"
end
end
end
local MarketService = game:GetService("MarketplaceService")
local Players = game:GetService("Players") -- this is a service, use :GetService() to get services instead of game.Service
if outcome == "time-up" then
status.Value = "Time up"
for _, player in Player:GetPlayers() do
if player:FindFirstChild("Contestant") then
xpcall(function() -- xpcall in case something goes wrong
-- local player = c -- this part is not needed at all
player.Tokens.Value += 20 * (if MarketService:UserOwnsGamePassAsync(player.UserId, GAMEPASS_ID_HERE) then 2 else 1)
-- i'm doing a slightly fancy thing on top called a ternary operation. you don't need to know what that is yet, all you need to know is that it multiplies 20 by 2 if user has the gamepass. multiply 20 by 1 if they don't
player.leaderstats.Survivals.Value += 1 -- yes, you can do number1 += number2 instead of number1 = number1 + number2.
end, warn) -- instead of breaking the whole script, gives a warning if something errors
end
end
end
yea
there’s a few ways to do it
the way i did is if condition then value1 else value2
there’s also condition and value1 or value2
but it can be a bit jank, and sometimes doesn’t work with strict typechecking so