I want to make a system where there is a hotbar that uses values, if the value is the same as the name of the item it will show the item and update the value.
For some reason,The image and value does not update. This is a script in the startergui for the hotbar:
while wait(0.1) do
for i,v in pairs(game.Players.LocalPlayer.PlayerScripts.Stats:GetChildren()) do
v.Changed:Connect(function(prop)
local icon = game.Players.LocalPlayer.PlayerScripts.Stats:WaitForChild(v.Parent.Name).Icon.Texture
if script.Slot1.Value == nil then
script.Slot1.Value = v.Name
hotbar.Slot1.Image.Image = icon
elseif script.Slot2.Value == nil then
script.Slot2.Value = v.Name
hotbar.Slot2.Image.Image = icon
elseif script.Slot3.Value == nil then
script.Slot3.Value = v.Name
hotbar.Slot3.Image.Image = icon
elseif script.Slot4.Value == nil then
script.Slot4.Value = v.Name
hotbar.Slot4.Image.Image = icon
elseif script.Slot5.Value == nil then
script.Slot5.Value = v.Name
hotbar.Slot5.Image.Image = icon
elseif script.Slot6.Value == nil then
script.Slot6.Value = v.Name
hotbar.Slot6.Image.Image = icon
elseif script.Slot7.Value == nil then
script.Slot7.Value = v.Name
hotbar.Slot7.Image.Image = icon
elseif script.Slot8.Value == nil then
script.Slot8.Value = v.Name
hotbar.Slot8.Image.Image = icon
elseif script.Slot9.Value == nil then
script.Slot9.Value = v.Name
hotbar.Slot9.Image.Image = icon
end
end)
end
end
if your in game each player has their own “PlayerGui”. so if your only getting StarterGui no one will be able to see it. here is some fixed code that should work theoretically
task.wait(.5)
local plr = game.Players.LocalPlayer
local plrGui = plr.PlayerGui
local gui = plrGui[GuiNameHere]
local guiBar = gui[GuiNameHere]
local guiImagesFolder = gui[FolderNameHere]
while true do
for index, slot in pairs(guiImagesFolder:GetChildren()) do
guiBar.Image = slot.Value
task.wait(.1)
end
end
tell me if it errors, also the layout of the gui might need to be changed a little bit. By that I mean you need to add a folder in the gui and name it whatever you want and then add all the slot things in that folder.
Sorry about that this code wouldn’t work if the slot values were to be out of order so I made this instead, also the slot values names need to be standalone numbers like 1, 2, 3, etc. instead of Slot1, Slot2, Slot3, etc. anyways here’s the code
task.wait(.5)
local plr = game.Players.LocalPlayer
local plrGui = plr.PlayerGui
local gui = plrGui["TestGui"]
local guiBar = gui["MainImageFrame"]
local guiImagesFolder = gui["ImageFolder"]
while true do
for i = 1, #guiImagesFolder:GetChildren(), 1 do
if guiImagesFolder[i] ~= nil then
local imageValue = guiImagesFolder[i].Value
guiBar.Image = imageValue
task.wait(.1)
end
end
end