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

Why does this script not work once I reset? (local script in startergui)

I have a local script, in startergui, that creates a surfacegui on a block. When the surfacrgui is clicked(it has a textbutton), it prompts you with a purchase. It works fine, but when I reset, it doesn't work anymore. Here's the code:

local p3 = game.Players.LocalPlayer

local pi3 = 43875114
local SG3 = Instance.new("SurfaceGui")
SG3.Parent = game.Workspace.don8
local TB3 = Instance.new("TextButton")
TB3.Parent = SG3
TB3.Size = UDim2.new(1,0,1,0)
TB3.Text = "Donation!(1000 Robux)"
TB3.BackgroundColor3 = BrickColor.White().Color
TB3.TextWrapped = true
TB3.FontSize = "Size60"

TB3.MouseButton1Down:connect(function()
Game:GetService("MarketplaceService"):PromptProductPurchase(p3, pi3)
    end)

Any ideas? All help is appreciated!

2 comments

0

yeah this isnt an answer i just wanted to say your donation price is more outrageous than a gold plated dominus. thats all.

0

It's just there for me to learn ._. Some guy actually bought the 100 robux one though! :D

1 answer

Instead of setting the Parent of the GUI to the part, you should insert the GUI into the player's PlayerGui and set the Adornee of the GUI to the part. This way, assuming you have StarterGui.ResetPlayerGuiOnSpawn set to true, it will remove the old one when reset.

local p3 = game.Players.LocalPlayer

local pi3 = 43875114
local SG3 = Instance.new("SurfaceGui")
SG3.Parent = p3.PlayerGui
SG3.Adornee = game.Workspace.don8
local TB3 = Instance.new("TextButton")
TB3.Parent = SG3
TB3.Size = UDim2.new(1,0,1,0)
TB3.Text = "Donation!(1000 Robux)"
TB3.BackgroundColor3 = Color3.new(1, 1, 1) --// No need to create a BrickColor, you can just use Color3.

TB3.TextWrapped = true
TB3.FontSize = Enum.FontSize.Size60 --// Better to use Enums for this.

TB3.MouseButton1Down:connect(function()
    Game:GetService("MarketplaceService"):PromptProductPurchase(p3, pi3)
end)

Hope this helped.

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