Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How Can I get a part when clicked to change the values/image in a Screen GUI's Frame?

I'm trying to create an inventory GUI. This GUI has a button that when clicked opens a Frame, this Frame holds the inventory(Slots,Items).

In the Inventory there is another Frame, this is the Slot where the item will be held. In this frame we have a number value for the amount of the item in the inventory.

When the player clicks a certain Object in the game I want this Value to Increase + 1 and to Change the asset ID of the imagelabel to whatever it should be.

Here is what I have.

Object's Click Detection Script. This is a local script inside a ClickDetector inside a brick.

local inv = game:GetService("StarterGui").GameGui.MainFrame.Inventory.InvtFrame
local invparts = inv:GetChildren()
local plr = game.Players.LocalPlayer

script.Parent.Parent.ClickDetector.MouseClick:connect(function(plr)
	local plr = game.Players.LocalPlayer
	if plr then
	for i, v in pairs(invparts) do
	   wait (0.5)
	   if v.SlotValue.Value == "" then
	    v.SlotValue.Value = "Wood"
	    v.Amount.Value = 0
	    v.SlotValue.Text = v.Amount.Value
	    v.SlotImage.Image = "http://www.roblox.com/asset/?id=539465370"
	    
	    break
	   elseif v.SlotValue.Value == "Wood" then 
	    v.Amount.Value = v.Amount.Value + 1
	    v.SlotLabel.Text = v.Amount.Value
	    break
	   end
	  end
	  
	 end
	end)?
	

The setup of the Inventory is: ScreenGUI<Frame<Textbutton<InvtFrame<ASlot<SlotValue, Amount, SlotLabel, SlotImage

1 answer

#Problem

The main problem is in line 1 where you set inv to be a gui element inside of StarterGui when you should really be accessing the PlayerGui. Do not get confused between the two. Remember that the StarterGui's contents are replicated to each player that joins. The contents are placed in the player's PlayerGui. For example, to access Player1's PlayerGui you would do something like local gui = game.Players.Player1.PlayerGui. The contents of the PlayerGui is what's being shown to the player and not the StarterGui.

#Solution

Replace the first part of the script with:

local PlayerGui = game.Players.LocalPlayer:WaitForChild("PlayerGui")
local inv = PlayerGui.GameGui.MainFrame.Inventory.InvtFrame

1 comment

0

Still does not work but Thanks for the information!

This discussion is preserved as it was. New answers, comments, and votes are closed.