PlayerGUI Issue in Representing StringValue

I have implemented a script to assist in communication between the player’s datastore and playergui, but I am now experiencing an issue with representing the player’s EquippedSkin vs. their owned skins. For example, the player can “equip” any of the skins in their inventory (intended), but my script permanently changes each frame’s “Owned” status to “Equipped”. Keep in mind that the player’s actual EquippedSkin value changes depending on their most recent equip. My previous script dealt with this issue, but this current one does not, and it seems to be disregarding a huge block of code.

Essentially, each frame (cost, in this case) should return to display “Owned” when a player equips another owned skin.

Here is a video to illustrate my problem:

This is what the content of the player object looks like:
0eebb62e0120ca3529c68a3ad08f54ab351f6d05

Script:

local Shop = script.Parent
local HUD = Shop.Parent.Parent
local Inventory = HUD.Inventory.Inventory
local InventoryItemTemplate = Inventory.InventoryGUI:WaitForChild("Template")
local InventoryScrollingFrame = Inventory:WaitForChild("ScrollingSkinLayout")

local Home = Shop:WaitForChild("Home")
local Skins = Shop:WaitForChild("Skins")

local HomeButton = Shop:WaitForChild("Home Button")
local SkinsButton = Shop:WaitForChild("Skins Button")
local KillEffects = Shop:WaitForChild("Kill Effects Button")
local SpecialisationsButton = Shop:WaitForChild("Malware Specialisations Button")

local ItemTemplate = script:WaitForChild("Template") -- Skin template is inside of the script
local UIChangeSFX = script["UI Change"]

-- Inventory
HUD:WaitForChild("InventoryToggle").MouseButton1Click:Connect(function()
	HUD:WaitForChild("Inventory").Inventory.Visible = not HUD:WaitForChild("Inventory").Inventory.Visible -- Inverts inventory status
	UIChangeSFX:Play()
end)

-- Inventory Setup and Interactions
function AddToFrame(v) -- We want to bring in the name of the Character into each frame, which is unique to that frame alone; this is the process that occurs after skin is bought from the Shop
	local Frame = InventoryItemTemplate:Clone()
	Frame.Name = v.Name
	Frame.Title.Text = v.Name
	Frame.Parent = InventoryScrollingFrame

	Frame.Icon.Image = v.HumanoidRootPart.MALWAREGUI.MALWARE.Image
	
	if game.Players.LocalPlayer.SkinInventory:FindFirstChild(v.Name) then
		Frame.Cost.Text = "Owned"
	end

	if game.Players.LocalPlayer.EquippedSkin.Value == v.Name then
		Frame.Cost.Text = "Equipped"
	end
	
	Frame.Cost.MouseButton1Click:Connect(function()
	
		local Result = game.ReplicatedStorage.AddToInventory:InvokeServer(v.Name, "Skin")
		if Result == "Bought" then
			Frame.Cost.Text = "Equipped"	
			print(Result)
			
			-- I believe this code block is being ignored. 
			for _, Object in pairs(Skins.ScrollingSkinLayout.Folder:GetChildren()) do
				if Object:IsA("Frame") and Object:FindFirstChild("Cost") then
					if game.Players.LocalPlayer.SkinInventory:FindFirstChild(Object.Name) then
						Object.Cost.Text = "Owned"
					end
				end
			end
			Frame.Cost.Text = "Equipped"
		end
	end)
end

As always, I am keen to further elaborate/provide further scripts for context if needed!

3 Likes

You’re using the Skins folder descendant which Skins is a child of Shop, whereas you’re trying to update the inventory. I’m not exactly sure how you’re UI is set up, but from the looks of it I would try:

for _, Object in ipairs(InventoryScrollingFrame:GetChildren()) do
3 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.