Green "Owned" Buttons do not show up when the player joins the game

  1. What do you want to achieve?
    I want the green “Owned” buttons to appear when the player joins the game.

  2. What is the issue?
    Well they don’t appear, since I am using a remote event (“PlayerRespawn”) which fires when the player dies (in my case, used for character model switching), therefore the skins including the template will appear in the skins shop but without the information that you own it.

  3. What solutions have you tried so far?
    Basically, I tried to fire the event when the player joins, that didn’t work properly as the templates would just duplicate tho the duplicates had the green owned buttons.

Using 2 scripts, a local and a server script.

  1. LocalScript
local player = game.Players.LocalPlayer
local shop = script.Parent.SkinStore.ScrollingFrame

-- Functions
function createShopTemplate(itemName,itemPrice,object,parent)

	local template = script:WaitForChild("Template"):Clone()
	template.Name = itemName
	template.ItemName.Text = itemName
	template.BuyButton.Text = itemPrice .." Coins"
	template.Price.Text = object:GetAttribute("Rarity")
	

	local Rarity = object:GetAttribute("Rarity")

	if Rarity == "Common" then
		template.Price.TextColor3 = Color3.new(0.784314, 0.784314, 0.784314)
	elseif Rarity == "Uncommon" then
		template.Price.TextColor3 = Color3.new(0.513725, 1, 0.364706)
	elseif Rarity == "Rare" then
		template.Price.TextColor3 = Color3.new(0.368627, 0.65098, 1)
	elseif Rarity == "Epic" then
		template.Price.TextColor3 = Color3.new(0.733333, 0.431373, 1)
	elseif Rarity == "Legendary" then
		template.Price.TextColor3 = Color3.new(1, 0.756863, 0.27451)
	end
	
	local previewedObject = object:Clone(); previewedObject.Parent = template.ViewportFrame
	
	local ori = 0
	
	local cam = Instance.new("Camera"); cam.Parent = template.ViewportFrame
	
	cam.CFrame = CFrame.new(object.Torso.Position + (object.Torso.CFrame.lookVector * 5), object.Torso.Position)
	
	template.ViewportFrame.CurrentCamera = cam
	
	template.Parent = parent
	
	--spawn(function()
		--while wait() do
			--ori += 1
			--previewedObject.Orientation = Vector3.new(0,ori,0)
		--end
	--end)
	
	return template
end


game.ReplicatedStorage.Events.PlayerRespawn.OnClientEvent:Connect(function()  
	-- Sort
	local orderedSkins = {}

	for i,v in pairs(game.ReplicatedStorage.Skins:GetChildren()) do
		table.insert(orderedSkins,v)
	end

	table.sort(orderedSkins,function(a,b) return a:GetAttribute("Price") < b:GetAttribute("Price") end)
	
	-- Shop
	for i,v in pairs(orderedSkins) do
		local frame = createShopTemplate(v.Name,v:GetAttribute("Price"),v, shop)
		
		if player.Inventory:FindFirstChild(v.Name) then -- I feel like this line is responsible for the appearing "Owned" button
			frame.BuyButton.Text = "Owned"
			frame.BuyButton.BackgroundColor3 = Color3.fromRGB(69, 230, 60)
			frame.BuyButton.BorderColor3 = Color3.fromRGB(69, 230, 60)
		end
		
		for i,v in pairs(player.Inventory:GetChildren()) do 

			local inventory = player:WaitForChild("Inventory")
			local rusa = player.PlayerGui:WaitForChild("MenuGui"):WaitForChild("JavanRusa"):WaitForChild("ScrollingFrame")
			local tiger = player.PlayerGui:WaitForChild("MenuGui"):WaitForChild("SiberianTiger"):WaitForChild("ScrollingFrame")
			if v.Name == "Dark Rusa" then
				rusa.JavanRusa3.Visible = true
				rusa.Rusa3Male.Visible = true
				rusa.Rusa3Female.Visible = true
			end
			if v.Name == "Light Rusa" then
				rusa.JavanRusa2.Visible = true
				rusa.Rusa2Male.Visible = true
				rusa.Rusa2Female.Visible = true
			end
			
			if v.Name == "Dark Orange Tiger" then
				tiger.Tiger3.Visible = true
				tiger.Tiger3Male.Visible = true
				tiger.Tiger3Female.Visible = true
			end
			if v.Name == "Light Orange Tiger" then
				tiger.Tiger4.Visible = true
				tiger.Tiger4Male.Visible = true
				tiger.Tiger4Female.Visible = true
			end

		end
		
		frame.BuyButton.MouseButton1Click:Connect(function()
			local result = game.ReplicatedStorage.Events.Buy:InvokeServer(v.Name)
			
			if result == "Brought" then
				frame.BuyButton.Text = "Owned"
				frame.BuyButton.BackgroundColor3 = Color3.fromRGB(69, 230, 60)
				frame.BuyButton.BorderColor3 = Color3.fromRGB(69, 230, 60)
			elseif result == "NotEnough" then
				frame.BuyButton.Text = "Not Enough Coins!"
				frame.BuyButton.BackgroundColor3 = Color3.fromRGB(255, 33, 33)
				wait(1)
				frame.BuyButton.Text = v:GetAttribute("Price") .." Coins"
				frame.BuyButton.BackgroundColor3 = Color3.fromRGB(218, 156, 32)
			end
		end)
	end
end)
  1. ServerScript
DataStore2.Combine("Key","Coins","Inventory")

-- Default Values
local defaultInventory = {}
--local defaultEquippedWeapon = ""

game.Players.PlayerAdded:Connect(function(player)
	local char = player.Character or player.CharacterAdded:Wait()

	-- Setup
	local coins = player:FindFirstChild("leaderstats").Coins

	local inventory = Instance.new("Folder",player); inventory.Name = "Inventory"
	--local equippedWeapon = Instance.new("StringValue",player); equippedWeapon.Name = "EquippedWeapon"

	-- Get DataStores
	local coinsDataStore = DataStore2("coins",player)
	local inventoryStore = DataStore2("Inventory8",player)
	--local equippedWeaponStore = DataStore2("EquippedWeapon",player)

	-- Functions
	local function updateCoins(newValue)
		coins.Value = newValue
	end

	local function updateInventory(newTable)
		-- Clear
		for i,v in pairs(inventory:GetChildren()) do v:Destroy() end

		-- Make a new one
		for i,v in pairs(newTable) do
			local itemValue = Instance.new("BoolValue",inventory); itemValue.Name = v
			
			for i,v in pairs(player.Inventory:GetChildren()) do 

				local inventory = player:WaitForChild("Inventory")
				local rusa = player.PlayerGui:WaitForChild("MenuGui"):WaitForChild("JavanRusa"):WaitForChild("ScrollingFrame")
				local tiger = player.PlayerGui:WaitForChild("MenuGui"):WaitForChild("SiberianTiger"):WaitForChild("ScrollingFrame")
				if v.Name == "Dark Rusa" then
					rusa.JavanRusa3.Visible = true
					rusa.Rusa3Male.Visible = true
					rusa.Rusa3Female.Visible = true
				end
				if v.Name == "Light Rusa" then
					rusa.JavanRusa2.Visible = true
					rusa.Rusa2Male.Visible = true
					rusa.Rusa2Female.Visible = true
				end
				
				if v.Name == "Dark Orange Tiger" then
					tiger.Tiger3.Visible = true
					tiger.Tiger3Male.Visible = true
					tiger.Tiger3Female.Visible = true
				end
				if v.Name == "Light Orange Tiger" then
					tiger.Tiger4.Visible = true
					tiger.Tiger4Male.Visible = true
					tiger.Tiger4Female.Visible = true
				end

			end
		end
		
	end
	-- Call functions right away
	updateCoins(coinsDataStore:Get(defaultValue))
	updateInventory(inventoryStore:Get(defaultInventory))

	-- Call functions for updates
	coinsDataStore:OnUpdate(updateCoins)
	inventoryStore:OnUpdate(updateInventory)

		
end)

game.ReplicatedStorage.Events.Buy.OnServerInvoke = function(player,itemName)

	local char = player.Character

	-- Get their data Store
	local coinsDataStore = DataStore2("coins",player)
	local inventoryStore = DataStore2("Inventory8",player)
	
	local item, inInventory

	local newTable = {}

	item = game.ReplicatedStorage.Skins:FindFirstChild(itemName)

	if player.Inventory:FindFirstChild(itemName) then inInventory = true end

	if item and item:GetAttribute("Price") then
		if not inInventory then

			-- If the player brought the item
			if player.leaderstats.Coins.Value >= item:GetAttribute("Price") then

				coinsDataStore:Increment(-item:GetAttribute("Price"))

				local itemValue = Instance.new("BoolValue",player.Inventory); itemValue.Name = item.Name

				for i,v in pairs(player.Inventory:GetChildren()) do table.insert(newTable,v.Name) end

				inventoryStore:Set(newTable)

				return "Brought"
			else
				return "NotEnough"
			end
		end
	end

end

Yeah and ofc the other script that ONLY fires the PlayerRespawn event.

I literally appreciate any kind of help.

Video for visualization of the problem:

External Media

Why don’t you make an event that doesn’t duplicate them but update them?

Thing is, it wasn’t supposed to duplicate and I have no idea how I would go about updating it

It is though, because PlayerSpawn creates the guis always.

do you have an idea where to put it in the code, an updating function maybe