Then I have a localscript within localplayer scripts that handles the entire pet buying process, here it is:
local plr = game.Players.LocalPlayer
local buyable = false
local db = false
repeat wait() until plr.Character
for i, v in pairs (plr.PlayerGui:WaitForChild('AdorneeUI'):GetDescendants()) do
if v:IsA("ImageButton") then
v.MouseButton1Click:Connect(function()
local numofpets = #game.ReplicatedStorage[plr.Name.."'s Inventory"].Pets:GetChildren()
if db == false and numofpets < 36 then
db = true
local function IsGem()
if v.Parent.Parent:FindFirstChild("Crystal") then
return true
else return false
end
end
if IsGem() == true then
if game.ReplicatedStorage[plr.Name.."'s Values"].Gems.Value >= v.Parent.Parent.Cost.Value then
buyable = true
end
else
if game.ReplicatedStorage[plr.Name.."'s Values"].Coins.Value >= v.Parent.Parent.Cost.Value then
buyable = true
end
end
if buyable == true then
game.ReplicatedStorage.Remotes.PetBuy:FireServer(v.Item.Text, IsGem(), v.Parent.Parent.Cost.Value)
buyable = false
end
wait(1)
db = false
end
end)
end
end
The problem here is, once the player resets and they click to buy a pet. It doesn’t do anything
no it does not reset the adornee to nil, and the adornee is not attached to the character, it is attached to a part that never gets destroyed and is stationary
if it makes any difference, the billboard gui is in the startergui
What I am assuming is that the player is cached, which means that whenever the player dies, the data is old, so to fix this you will need to add a function that updates the player on spawn.
Then I have a localscript within localplayer scripts that handles the entire pet buying process, here it is:
local plr = game.Players.LocalPlayer
local buyable = false
local db = false
repeat wait() until plr.Character
for i, v in pairs (plr.PlayerGui:WaitForChild('AdorneeUI'):GetDescendants()) do
if v:IsA("ImageButton") then
v.MouseButton1Click:Connect(function()
local numofpets = #game.ReplicatedStorage[plr.Name.."'s Inventory"].Pets:GetChildren()
if db == false and numofpets < 36 then
db = true
local function IsGem()
if v.Parent.Parent:FindFirstChild("Crystal") then
return true
else return false
end
end
if IsGem() == true then
if game.ReplicatedStorage[plr.Name.."'s Values"].Gems.Value >= v.Parent.Parent.Cost.Value then
buyable = true
end
else
if game.ReplicatedStorage[plr.Name.."'s Values"].Coins.Value >= v.Parent.Parent.Cost.Value then
buyable = true
end
end
if buyable == true then
game.ReplicatedStorage.Remotes.PetBuy:FireServer(v.Item.Text, IsGem(), v.Parent.Parent.Cost.Value)
buyable = false
end
wait(1)
db = false
end
end)
end
end
The problem here is, once the player resets and they click to buy a pet. It doesn’t do anything
That would not work again because when you buy / click on coins for example it does not need to save anything when it resets etc. it just registers the click even when the player has reset. The billboard gui works the same way as the coins therefor not requiring it to be saved