How to set text of a text button based on items in player backpack

I have a GUI where you can purchase tools and i have them save so i want to make it so that if theyre in ur backpack they say purchased but i have a script for them inside the textbutton but almost all of the time it doesn’t work
Edit: i think after you purchase an item and rejoin it doesnt work but if you purchase the item again and rejoin it does

local player = game.Players.LocalPlayer

if player.Backpack:FindFirstChild("Bucket") then
	script.Parent.Text = ("Purchased")
	script.Parent.LocalScript.Disabled = true
end
1 Like

Most likely wouldn’t work because the script would check if it had it in their backpack before they would even start actually playing the game.

Better if you checked if they bought it then send that over to the client to disable the button (RemoteEvent or The Client).

OR

You wait until a child is added into the backpack with .ChildAdded with the name of “Bucket”.

Is this a gamepass or a developer product?

its neither its a item you can buy with in game currency

Ah so it’s either saved with a datastore or bought per visit.

So you can tell the client to disable the purchase button and change the text when you check if they have it on the server.

yea its saved with a datastore

local player = game.Players.LocalPlayer

function check(child)
  if ((child.ClassName ~= "Tool") or (child.Name ~= "Bucket")) then return end
  script.Parent.Text = "Purchased"
  script.Parent.LocalScript.Disabled = true
end

for _, v in next, player.Backpack:GetChildren() do
  check(v)
end

player.Backpack.ChildAdded:Connect(check)
1 Like
--SERVER
--GetData
--Check if they have item
--if they do
--Fire remote to client
Remote:FireClient(Player)
--CLIENT
Remote.OnClientEvent:Connect(function()
     --turn text to purchased
end)

Or you can try the idea above (the reply) with the solution of:

How are you saving it? How are you loading the data? Maybe the saving/loading part of your DataStrore isn’t working correctly?