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
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.
Replace the first part of the script with:
local PlayerGui = game.Players.LocalPlayer:WaitForChild("PlayerGui") local inv = PlayerGui.GameGui.MainFrame.Inventory.InvtFrame