Can somebody tell me what is wrong with my script? I want it where if the player buys the dev product it would change the text of the player’s gui. Thi script is in a server script
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local productFunctions = {}
productFunctions[1112608554] = function(receipt, player)
if player.Character and player.Character:FindFirstChild("Humanoid") then
local points = game.Players.LocalPlayer.LevelsInfo.Level
player.PlayerGui.GUI.MainFrame.Breathing.Value.Text = 0
player.PlayerGui.GUI.MainFrame.Health.Value.Text = 0
player.PlayerGui.GUI.MainFrame.Speed.Value.Text = 0
player.PlayerGui.GUI.MainFrame.Total.Value.Text = points.Value
player.Character.Humanoid.Health = player.Character.Humanoid.MaxHealth
return true
end
end
local function processReceipt(receiptInfo)
local player = Players:GetPlayerByUserId(receiptInfo.PlayerId)
if not player then
return Enum.ProductPurchaseDecision.NotProcessedYet
end
local handler = productFunctions[receiptInfo.ProductId]
local success, result = pcall(handler, receiptInfo, player)
if not success or not result then
warn("Error occurred while processing a product purchase")
print("\nProductId:", receiptInfo.ProductId)
print("\nPlayer:", player)
return Enum.ProductPurchaseDecision.NotProcessedYet
end
return Enum.ProductPurchaseDecision.PurchaseGranted
end
MarketplaceService.ProcessReceipt = processReceipt
Your probably better off using a Remote Event to tell the client to make these changes as they are just visual
productFunctions[1112608554] = function(receipt, player)
if player.Character and player.Character:FindFirstChild("Humanoid") then
RemoteEvent:FireClient(player.UserId, points.Value) -- Pass the points.Value so Total.Value can be edited
player.Character.Humanoid.Health = player.Character.Humanoid.MaxHealth
return true
end
end
-- Local Script preferably should be a child of GUI.MainFrame
local RemoteEvent = Where ever your remote event is located should be Replicated Storage
local function FunctionName(Points)
player.PlayerGui.GUI.MainFrame.Breathing.Value.Text = 0
player.PlayerGui.GUI.MainFrame.Health.Value.Text = 0
player.PlayerGui.GUI.MainFrame.Speed.Value.Text = 0
player.PlayerGui.GUI.MainFrame.Total.Value.Text = Points
end
RemoteEvent.OnClientEvent:Connect(FunctionName)
Also you can’t call “LocalPlayer” from a script it has to be a local script inside of
StarterGui
StarterPack
StarterPlayer → StarterPlayerScripts
StarterPlayer → StarterCharacterScripts
Hm, thats weird I’m getting a warning and then the dev product doesn’t work
local function processReceipt(receiptInfo)
local player = Players:GetPlayerByUserId(receiptInfo.PlayerId)
if not player then
return Enum.ProductPurchaseDecision.NotProcessedYet
end
local handler = productFunctions[receiptInfo.ProductId]
local success, result = pcall(handler, receiptInfo, player)
if not success or not result then
warn("Error occurred while processing a product purchase") -- The warning
print("\nProductId:", receiptInfo.ProductId)
print("\nPlayer:", player)
return Enum.ProductPurchaseDecision.NotProcessedYet
end
return Enum.ProductPurchaseDecision.PurchaseGranted
end
MarketplaceService.ProcessReceipt = processReceipt
Hmm i dont see your script on the Developer page for Developer Products try reading up on Dev products and see if you find anything ill do the same and get back you if i find anything