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

When player purchases in-game, server chat. Not working?

Asked by 5 years ago
local Players = game:GetService("Players")
local MarketplaceService = game:GetService("MarketplaceService")
local PurchaseHistory = game:GetService("DataStoreService"):GetDataStore("PurchaseHistory")

function onPlayerPurchased (player)
    game:GetService("StarterGui"):SetCore("ChatMakeSystemMessage",{
    Text = ".. player.Name .. " has bought "receiptInfo.PlayerId .. ":" .. receiptInfo.PurchaseId. 
    if PurchaseHistory:GetAsync(playerProductKey) then
    return Enum.ProductPurchaseDecision.PurchaseGranted
    end

    Color = Color3.new(255,255,255);
    Font = Enum.Font.SourceSansBold; 
    FontSize = Enum.FontSize.Size18;
})
end

local player = game:GetService("Players"):GetPlayerByUserId(receiptInfo.PlayerId)
if not player then
        return Enum.ProductPurchaseDecision.NotProcessedYet
end

    PurchaseHistory:SetAsync(playerProductKey, true)    
    return Enum.ProductPurchaseDecision.PurchaseGranted     
end
end

As a Local script in StarterGUI.

0
You can't use DataStores in local scripts Rare_tendo 3000 — 5y
0
Please properly indent your code. Properly indented code is easier to read and debug. User#21908 42 — 5y
0
Also as the comment above stated: You cannot access the DataStoreService from the client or more specifically, a LocalScript. User#21908 42 — 5y

Answer this question