When a player purchases a dev product this script is supposed to enable a Gui for all players, wait 60 seconds and disable it but I get this “ServerScriptService.Script:17: attempt to index nil with ‘Gui’”
Script:
local MarketplaceService = game:GetService("MarketplaceService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local players = game:GetService("Players")
local productId = 000000000
local function processReceipt(receiptInfo)
local player = players:GetPlayerByUserId(receiptInfo.PlayerId)
if not player then
return Enum.ProductPurchaseDecision.NotProcessedYet
end
if player then
players:GetPlayers().PlayerGui.Gui.Enabled = true
wait(60)
players:GetPlayers().PlayerGui.Gui.Enabled = false
end
end
MarketplaceService.ProcessReceipt = processReceipt
Fire a RemoteEvent to the client from the server, when you want the gui to popup / go away.
Also include a value (true/false) in that remote, that you’re firing to the client.
On the client, make a function that listens to this RemoteEvent, and make it popup the GUI if your value sent is true, or go away if your value sent is false
Oh! or you could just remove it from the client after 60 secs in the client script, no need to fire a remote twice.
Here is the basics:
--SERVER
local TestRemote = ReplicatedStorage:WaitForChild("TestRemote")
-- Inside your processReceipt function
TestRemote:FireAllClients()
--CLIENT
local TestRemote = ReplicatedStorage:WaitForChild("TestRemote")
local Gui = script.Parent
TestRemote.OnClientEvent:Connect(function()
-- The reason for that I check if Gui is already enabled, is that there's no reason to change the value, if it's already set to Enabled. And vice versa with when we disable the Gui.
if not Gui.Enabled then
Gui.Enabled = true
end
wait(60)
if Gui.Enabled then
Gui.Enabled = false
end
end)
I found out it was being caused by a donation board in my game which uses dev products, after removing the donation board everything works now. Thanks!
I’m glad to hear that. You could as Deca have posted also change the gui.enabled directly from the server, but I wouldn’t personally go with that approach myself. With my approach you have the posibility to even tween the gui away.