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

Why does this DevProduct script not work creating the Instances? Output does not give any errors

It's supposed to create a SurfaceGui with a textbutton, that, when clicked, prompts me with a DevProduct. Output doesn't give any errors. Also, this is a localscript in StarterGui.

Code:

game.Players.PlayerAdded:connect(function(p)

local pi = 43873080
local SG = Instance.new("SurfaceGui")
SG.Parent = game.Workspace.don8
local TB = Instance.new("TextButton")
TB.Parent = SG
TB.Size = UDim2.new(1,0,1,0)
TB.Text = "Click Me!"

TB.MouseButton1Down:connect(function()
	Game:GetService("MarketplaceService"):PromptProductPurchase(p, pi)
    end)
end)

1 answer

✓ Accepted answer

Try this, place the script inside the StarterGui.

local p = game.Players.LocalPlayer

local pi = 43873080
local SG = Instance.new("SurfaceGui")
SG.Parent = p:WaitForChild("PlayerGui")
SG.Adornee = game.Workspace.don8
local TB = Instance.new("TextButton")
TB.Parent = SG
TB.Size = UDim2.new(1,0,1,0)
TB.Text = "Click Me!"

TB.MouseButton1Down:connect(function()
    game:GetService("MarketplaceService"):PromptProductPurchase(p, pi)
end)

Explaination:

PlayerAdded does not fire for the player entering, because the player is created before the scripts. (Might be wrong on this one, but I surely know that PlayerAdded does not fire for the player entering atleast)

The solution is simple, first create a variable named "p" and point it to the localplayer, then parent SGto the PlayerGui and set it's adornee to game.Workspace.don8. Oh and one last thing, don't use Game, it's deprecated, instead use game, hope it helps.

2 comments

0

Thanks! That worked!

0

You're welcome :)

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