Making a store put items in playback pack and saving them in store data

I am trying to make a storeGui for my game. Upon purchase the item will be put in the players backpack and when they leave and rejoin that item will still be purchased. I have made the script for that can mark items as owned in a shop gui I made, but I am not sure on how to go about the rest. Here is my code so far: (I am amature scripter so if you see anything I can improve/change that would be appreciated also)

–Made by Its4Realzies with help from by zamd157
local sP = script.Parent

–Text colors
local red = Color3.fromRGB(221, 57, 57)
local yellow = Color3.fromRGB(245, 184, 41)
local grey = Color3.fromRGB(145, 145, 145)

–Lock, Unlock and Own item
local function updateItem(item, status)

local parentFrame = item

if status == "Owned" or status == "Locked" then
	parentFrame.BuyButton.TextColor3 = grey
	parentFrame.Info.TextColor3 = grey
	parentFrame.Title.TextColor3 = grey
	parentFrame.Pic.Image = parentFrame.Pic.Unsaturated.Value
	if status == "Owned" then
		parentFrame.BuyButton.Text = "Owned"
		parentFrame.isOwned.Value = true
	else
		parentFrame.BuyButton.Text = "Locked"
		parentFrame.isLocked.Value = true
	end
else
	parentFrame.BuyButton.TextColor3 = yellow
	parentFrame.Info.TextColor3 = yellow
	parentFrame.Title.TextColor3 = yellow
	parentFrame.Pic.Image = parentFrame.Pic.Saturated.Value
	parentFrame.BuyButton.Text = parentFrame.Cost.Value .. "pts"
	parentFrame.isLocked.Value = false
	
end

end

local waitCheck = false
local function doPurchase(button)
local parentFrame = button.Parent

local player = game:GetService("Players").LocalPlayer
local leaderstats = player.leaderstats
local pointStat = leaderstats and leaderstats:FindFirstChild("Points")

local isOwned = parentFrame.isOwned.Value
local isLocked = parentFrame.isLocked.Value
if isOwned ~= true and isLocked ~= true then
	
	if pointStat.Value >= parentFrame.Cost.Value then
		updateItem(parentFrame, "Owned")
		pointStat.Value = pointStat.Value - parentFrame.Cost.Value
		
		--Unlocks upgrade	
		if parentFrame.isItem.Value == true then
			updateItem(sP.Store:FindFirstChild(parentFrame.Name + 4), "Unlocked") 
		end	
	elseif waitCheck ~= true then
		waitCheck = true
		parentFrame.BuyButton.TextColor3 = red
		parentFrame.BuyButton.Text = "Insufficient pts"
		wait(1)
		waitCheck = false
		parentFrame.BuyButton.TextColor3 = yellow
		parentFrame.BuyButton.Text = parentFrame.Cost.Value .. "pts"
	end
end

end

for i, button in ipairs (sP.Store:GetDescendants()) do

if button.ClassName == 'TextButton' and button.Name == "BuyButton" then

	button.MouseButton1Click:Connect(function() -- Give it an anonymous function
		doPurchase(button) -- Fire the function with the button parameter
	end)
end

end

local shopEnabled = false
–Open and close shop
local function doUpdateShop()
if shopEnabled == false then
shopEnabled = true
sP.Store.Visible = true
else
shopEnabled = false
sP.Store.Visible = false
end
end

sP.StoreButton.MouseButton1Click:Connect(doUpdateShop)

Is there someway I can put like boolvalues on starterplayer to know if they have them or not or something???

Btw this is a local script if that may be a problem

Datastores saving needs to always be done in the server. using TCP/IP (Remote events remote functions etc) make a server script taht will get the data store data using .PlayerAdded event and saving it using .PlayerRemoving. You could do a datastore that contains a value that determines if the user owns a product

Alteratively if your store uses a gamepass for example you can simply check if the user owns the gamepass

Ok can you elaborate on “You could do a datastore that contains a value that determines if the user owns a product”