Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why won't my currency shop button give the money?

So I have a currency shop that give you money. And it will let you buy the developer product but doesn't give the money.

The local script on the button --

MPS = game:GetService("MarketplaceService")
id = 1037851428
local player = game.Players.LocalPlayer

script.Parent.MouseButton1Click:connect(function()
	MPS:PromptProductPurchase(player, id)
end)

Script in ServerScriptService --

local MPS = game:GetService("MarketplaceService")

MPS.ProcessReceipt = function(receiptInfo)
	if receiptInfo.ProductId == 1037851428 then
	    local player = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)
	    player.leaderstats.Money.Value = player.leaderstats.Money.Value + 250
		    return Enum.ProductPurchaseDecision.PurchaseGranted
end
end

please help me :(

2 comments

0

You would need a remote event since LocalScripts don't change value objects nor do they replicate for other players in the server.

0

A remote event is a instance event you can fire to give information from the client to the server or you can send information from the server to a client. If you need more information, here is a link to the wiki page about remote event. (https://developer.roblox.com/en-us/api-reference/class/RemoteEvent)

1 answer

local remoteevent = game.ReplicatedStorage.RemoteEvent
MPS = game:GetService("MarketplaceService")
id = 1037851428
local player = game.Players.LocalPlayer

script.Parent.MouseButton1Click:connect(
    function()
        MPS:PromptProductPurchase(player, id)
    end
)

local MPS = game:GetService("MarketplaceService")

MPS.ProcessReceipt = function(receiptInfo)
    if receiptInfo.ProductId == 1037851428 then
        local player = game.Players:GetPlayerByUserId(receiptInfo.UserId)
remoteevent:FireServer(player)
        return Enum.ProductPurchaseDecision.PurchaseGranted
    end
end

remember, it's userid not playerid and use a remote event (make one called RemoteEvent)

server script

local remoteevent = game.ReplicatedStorage.RemoteEvent
remoteevent.OnServerEvent:Connect(function(player)
     player.leaderstats.Money.Value = player.leaderstats.Money.Value + 250
end)

2 comments

0

It is still not giving the coins :(

0

Also whats a remote event and how do I create one?

This discussion is preserved as it was. New answers, comments, and votes are closed.