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

HElP! if ONE player purchases a Dev Product, how would the whole server receives it's benefit?

Asked by 5 years ago
Edited 5 years ago

Hello! Recently, I've been trying to fix one of my scripts.

This script is linked to a Dev Product. When the product is bought, it is intended to give everyone in the server + 50 Tokens (including the player who bought it!).

But... when the player purchases the product, nothing happens!

I tested the script out originally so that only the player who bought it received the + 50 Tokens, which worked. But the script which is supposed to give every player in the server the + 50 Tokens didn't... (FYI, both scripts were placed in ServerScriptService)

This is the script which only gives one player the + 50 Tokens. (Script1)

local MarketplaceService = game:GetService('MarketplaceService')
local devproductId = 389417210 -- The ID of the dev product.

MarketplaceService.ProcessReceipt = function(receiptInfo)
    for i, player in ipairs(game.Players:GetChildren()) do
        if player.userId == receiptInfo.PlayerId then
            if receiptInfo.ProductId == devproductId then

                -- Receive tokens
                player.leaderstats.Tokens.Value = player.leaderstats.Tokens.Value + 50
            end
        end
    end
    return Enum.ProductPurchasedDescision.PurchaseGranted
end

After finding that the other script (script above) worked, I tried this script, which is the script that is supposed to give everyone in the server + 50 Tokens. (Script2)

local MarketplaceService = game:GetService('MarketplaceService')
local devproductId = 389417210 -- The ID of the dev product.
local players = game:GetService("Players")

MarketplaceService.ProcessReceipt = function(receiptInfo)
    for i, player in ipairs(game.Players:GetChildren()) do
        if player.userId == receiptInfo.PlayerId then
            if receiptInfo.ProductId == devproductId then

                -- Receive Tokens
                players.leaderstats.Tokens.Value = players.leaderstats.Tokens.Value + 50
            end
        end
    end
    return Enum.ProductPurchasedDescision.PurchaseGranted
end

I'm not sure if I'm missing something, or if something is wrong. I'm relatively new to scripting, so Script2 is probably completely wrong.

If anyone could help me out a bit, that would be great!

0
Players is not a actual "player" its a Service User#23365 30 — 5y
0
Use game:GetService("Players"):GetPlayers() get service is the best way to get a service and getplayers is the recommended way to get players User#21908 42 — 5y
0
userId is deprecated, use UserId. You know that GetPlayerByUserId exists right? User#19524 175 — 5y
0
Simply remove the check you're making: if player.userId == receiptInfo.PlayerId then gullet 471 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

That's easy, You need to make a for loop on the players.

for number, plr ipairs(game.Players:GetChildern()) do
    -- Receive token

    plr.leaderstats.Tokens.Value = plr.leaderstats.Tokens.Value + 50
end

For loops for the victory!

0
Hope it helps! sahar1213 72 — 5y
0
It still has the same outcome. Nothing happens. :( Trxxsure 0 — 5y
0
Wouldn't I need a variable for the 'plr'? Trxxsure 0 — 5y
Ad

Answer this question