Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
Peeshavee 226 Moderation Voter
7 years ago

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

Log in to vote
2
Answered by
Cesire 45
7 years ago
Edited 7 years ago

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.

0
Thanks! That worked! Peeshavee 226 — 7y
0
You're welcome :) Cesire 45 — 7y
Ad

Answer this question