Show Item In Inventory GUI

Hi,

Ive been trying to make an Inventory GUI which shows the player bought items such as the gamepasses i have for sale within my game.

Currently i have an game pass called Rainbow Trail which gives the player a trail once they have bought it.

I have an Inventory GUI with an image label which i’d like to make visible if the player has the gamepass. Ive seen tutorials for an inventory and i might need to clone it then make it visible?

local MarketPlaceService = game:GetService("MarketplaceService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local Players = game:GetService("Players")

local RainbowpassID = 86294878

local ItemFrame = script.Parent.Frame.ScrollingFrame


local Trail = game.ServerStorage["RainbowTrail"]

local rainbowbuy = false



Players.PlayerAdded:Connect(function(player)

	player.CharacterAdded:Connect(function(character) -- This was needed

		local success, hasPass = pcall(function() -- Changing the pcall to the correct format
			return MarketPlaceService:UserOwnsGamePassAsync(player.UserId, RainbowpassID)
		end)

		if success then -- Checking if successful
			if hasPass then -- Checking if the player has the

				local clone = script.Parent.Frame.ScrollingFrame.ImageLabel:Clone()

				clone.Visible = true



			end

		end

	end)

end)

Here’s my current script which is located in a local script inside of the inventory GUI.

I used the same script to fetch whether the player has the Gamepass as i used to give the player the rainbow trail and it works in doing that.

Im just unsure on the part of the code which will clone a new item space and show an imagelabel in the inventory.

if success then -- Checking if successful
			if hasPass then -- Checking if the player has the

				local clone = script.Parent.Frame.ScrollingFrame.ImageLabel:Clone()

				clone.Visible = true



			end

		end

Im assuming that the cloning would be done here but my current clone script does not work.

Can anyone help me please? Ive looked everywhere, googled everything but i cannot find a script which displays gamepasses in an Inventory GUI in game.

Many Thanks! Tia

It is because in a local script, Players:PlayerAdded will fire when someone else joins, and not the local player. Therefore it will make the other player show the pass. Instead, try some along the lines of this:

local MarketPlaceService = game:GetService("MarketplaceService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local Players = game:GetService("Players")
local localPlayer = Players.LocalPlayer
local RainbowpassID = 86294878

local ItemFrame = script.Parent.Frame.ScrollingFrame


local Trail = game.ServerStorage["RainbowTrail"]

local rainbowbuy = false



localPlayer.CharacterAdded:Connect(function()
	local success, hasPass = pcall(function() -- Changing the pcall to the correct format
		return MarketPlaceService:UserOwnsGamePassAsync(localPlayers.UserId, RainbowpassID)
	end)

	if success then -- Checking if successful
		if hasPass then -- Checking if the player has the

			local clone = script.Parent.Frame.ScrollingFrame.ImageLabel:Clone()

			clone.Visible = true



		end

	end

end)

Let me know if this works. If it doesn’t then I might’ve not replace all instances of player with localPlayer or you might need to try a different way of checking wether the player has the pass.

ye it still doesnt work, i think it might be the checking whether player has pass

you might need to put in your original script in a server script, and change some of the cloning code around so instead script.Parent… etc its player.StarterGUI… etc. Your original script was probably intended to be used server side and not on the client.

1 Like

Similarly like what @ EJQuik89, use “LocalPlayer” to refer to the player itself since you are using a localscript. Also, one quick note to change is the “ServerStorage” line in the variable for “Trail”, clients cannot access the serverstorage so I changed it to ReplicatedStorage. You are also missing the line in which who is the “clone” 's parent is.

Try this and let me know if it works…? :

local MarketPlaceService = game:GetService("MarketplaceService")

local player = game:GetService("Players").LocalPlayer

local RainbowpassID = 86294878

local ItemFrame = script.Parent.Frame.ScrollingFrame


local Trail = game.ReplicatedStorage["RainbowTrail"] -- Don't Put Serverstorage as client can't access serverstorage

local rainbowbuy = false


wait(player.Character:WaitForChild("HumanoidRootPart"))
local success, hasPass = pcall(function() -- Changing the pcall to the correct format
	return MarketPlaceService:UserOwnsGamePassAsync(player.UserId, RainbowpassID)
end)

if success then -- Checking if successful
	if hasPass then -- Checking if the player has the
	local clone = script.Parent.Frame.ScrollingFrame.ImageLabel:Clone()
--clone.Parent = [???]
	clone.Visible = true
	end
	end

This didnt work either. i think it is struggling to clone the item slot

In your script, you have only cloned the object but you didn’t set its parent to anything yet. Where do you want the cloned instance, ImageLabel, to be a descendant of? The scrolling frame? the frame?

	local clone = script.Parent.Frame.ScrollingFrame.ImageLabel:Clone()
clone.Parent = script.Parent.Frame.ScrollingFrame
	clone.Visible = true

??

2 Likes

Thankyou it works now haha! Do you know how i’d change the cloned image label’s image thru the script also?

You’re welcome!
Yes, you could simply do: clone.Image = "http://www.roblox.com/asset/?id=".. IMAGEID

2 Likes

Thankyou it works now :slight_smile:

1 Like