I have this script which gives the player 100 in-game money if they own the gamepass I made. The problem is, it gives them 100 cash each time they join. Is there a way to fix this?
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local gamePassID = 19020734
local function onPlayerAdded(player)
local hasPass = false
local success, message = pcall(function()
hasPass = MarketplaceService:UserOwnsGamePassAsync(player.UserId, gamePassID)
end)
if not success then
warn("Error while checking if player has pass: " .. tostring(message))
return
end
if hasPass == true then
print(player.Name .. " owns the game pass with ID " .. gamePassID)
player:WaitForChild("leaderstats"):WaitForChild("Money").Value +=100
end
end
Players.PlayerAdded:Connect(onPlayerAdded)
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local gamePassID = 19020734
local function onPlayerAdded(player)
local hasPass = false
local success, message = pcall(function()
hasPass = MarketplaceService:UserOwnsGamePassAsync(player.UserId, gamePassID)
end)
if not success then
warn("Error while checking if player has pass: " .. tostring(message))
return
end
if hasPass == true then
print(player.Name .. " owns the game pass with ID " .. gamePassID)
player:FindFirstChild("leaderstats"):FindFirstChild("Money").Value +=100
end
end
Players.PlayerAdded:Connect(onPlayerAdded)
Why would you want it to be a gamepass though? If it’s a gamepass then they can only get it once but if you use dev products like @Turned_Away has said, they can by it multiple times while it gives 100 per purchase
local MarketPlaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local productId = 'productid'
script.Parent.MouseButton1Down:Connect(function(promptPurchase)
local player = Players.LocalPlayer
MarketPlaceService:PromptProductPurchase(player, productId)
end)
Then fire a remote event to give the player the cash?