-
What do you want to achieve?
If you buy the product you should get 1000 in-game currency. -
What is the issue?
player.CurrencyCash.Cash.Value = player.CurrencyCash.Cash.Value + 1000
-
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
Yes, but I am new to scripting and I don’t understand the error mesage.
The Curency Script on the Server:
local currencyName = "Cash"
local DataStore = game:GetService("DataStoreService"):GetDataStore("TestDataStore")
game.Players.PlayerAdded:Connect(function(player)
local folder = Instance.new("Folder")
folder.Name = "CurrencyCash"
folder.Parent = player
local currency = Instance.new("IntValue")
currency.Name = currencyName
currency.Parent = folder
local ID = currencyName.."-"..player.UserId
local savedData = nil
pcall(function()
savedData = DataStore:GetAsync(ID)
end)
if savedData ~= nil then
currency.Value = savedData
print("Data Loaded")
else
-- new Player
currency.Value = 10
print("New player to the game")
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local ID = currencyName.."-"..player.UserId
DataStore:SetAsync(ID,player.CurrencyCash.Cash.Value)
end)
game:BindToClose(function()
-- When Game is ready to shut down
for i, player in pairs(game.Players:GetPlayers()) do
if player then
player:Kick("This game is shutting down")
end
end
wait(5)
end)
-- This for testing with cubes
workspace:WaitForChild("Red").ClickDetector.MouseClick:Connect(function(player)
player.CurrencyCash.Cash.Value = player.CurrencyCash.Cash.Value - 50
end)
workspace:WaitForChild("Green").ClickDetector.MouseClick:Connect(function(player)
player.CurrencyCash.Cash.Value = player.CurrencyCash.Cash.Value + 5
end)
-- There is the problem
local MPS = game:GetService("MarketplaceService")
MPS.ProcessReceipt = function(receiptInfo)
if receiptInfo.ProductId == 996079489 then
local player = game.Players:GetPlayerByUserId(receiptInfo.ProductId)
print("Player purchased")
player.CurrencyCash.Cash.Value = player.CurrencyCash.Cash.Value + 1000
print("Recieved gamepass")
return Enum.ProductPurchaseDecision.PurchaseGranted
end
end
The Local Button script:
MPS = game:GetService("MarketplaceService")
id = 996079489
local player = game.Players.LocalPlayer
script.Parent.MouseButton1Click:Connect(function()
MPS:PromptProductPurchase(player, id)
end)
10:28:18.516 - ServerScriptService.CurrencyScript:68: attempt to index nil with ‘CurrencyCash’
10:28:18.518 - Script ‘ServerScriptService.CurrencyScript’, Line 68
It works but the Problem is that you not get the Cash. Thank You for Helping