I have a surfacengui which should let players purchase a gamepass, and it works fine, until the player resets. because then the surfacegui breaks. For example when hovering over the button with the mouse, it should change color, but after reset it doesnt do anything. It also doesnt error or warn. The code is in a localscript and i have filtering enabled. what did i do wrong and how can i fix it?
local localplayer = script.Parent.Parent.Parent.Parent.Parent.Parent
local char = localplayer.Character or localplayer.CharacterAdded:wait()
local surfacegui = script.Parent.Parent.Parent.Parent
surfacegui.Adornee = game.Workspace.SuitScreen
game.Workspace:WaitForChild(char,20)
function isAuthenticated(plr) -- checks to see if the player owns your pass
return game:GetService("MarketplaceService"):PlayerOwnsAsset(plr, 625306888)
end
game.Players.PlayerAdded:connect(function(plr) --adjusts gui if player has pass
if isAuthenticated(plr) then
script.Parent.Text = "Select!"
end
end)
char.Humanoid.Died:connect(function()
surfacegui.Adornee = game.Workspace.SuitScreen
if isAuthenticated(localplayer) then
if localplayer:FindFirstChild("Bluesuit") ~= nil then
script.Parent.Text = "Selected!"
else
script.Parent.Text = "Select!"
end
end
end)
game:GetService("MarketplaceService").PromptPurchaseFinished:connect(function(plr,assetId,isPurchased) --activates item
if isPurchased then
if plr == localplayer then
if assetId == 625306888 then
script.Parent.Text = "Select!"
end
end
end
end)
script.Parent.MouseButton1Click:connect(function() --prompt purchase/select item
if not isAuthenticated(localplayer) then
game:GetService("MarketplaceService"):PromptPurchase(localplayer,625306888)
elseif script.Parent.Text ~= "Selected!" then
script.Parent.Text = "Selected!"
local value = Instance.new("CFrameValue")
value.Parent = localplayer
value.Name = "Bluesuit"
end
end)
script.Parent.Parent.MouseEnter:connect(function() --button darker hover
script.Parent.Parent.ImageColor3 = Color3.new(195/255,195/255,195/255)
end)
script.Parent.Parent.MouseLeave:connect(function() --button normal no hover
script.Parent.Parent.ImageColor3 = Color3.new(255/255,255/255,255/255)
end)

2 comments
help
Did you have it so that the code repeats on CharacterAdded function or if the localscript is ran again on player respawn?