-
What do you want to achieve? Keep it simple and clear!
Hello,
im kinda new to this thing so ill try to be as helpful as possible
basically, I have a backpack/hotbar system that will exclusively work in studio, breaking randomly in the Roblox Player App. -
What is the issue? Include screenshots / videos if possible!
I have designed a custom backpack system, similar to Fisch or Jailbreak, however the Roblox Player seems to just not like it, as certain items will just not appear in the gui (Studio works completely fine) -
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
lots, really just looking up forum posts similar to the one I am writing.
The hierarchy of the GUI:
studio screenshot of gui (what it should look like):
player screenshot 1(what I want to happen)
player screenshot 2(what usually happens)
-- This is the source for the hotbar system that is broken
local template = script.Parent:WaitForChild("template")
local uis = game:GetService("UserInputService")
local players = game:GetService("Players")
local player : Player = players.LocalPlayer
local char : Model = player.Character or player.CharacterAdded:Wait()
local backpack : Backpack = player.Backpack
local hum : Humanoid = char:WaitForChild("Humanoid")
local animator : Animator = hum:WaitForChild("Animator")
local equipped = nil
local attempts = 0
local Items = {}
local Frames = {}
local PreferredOrder = {} --not implemented, not problem
local NumberKeycodes = {
"One",
"Two",
"Three",
"Four",
"Five",
"Six",
"Seven",
"Eight",
"Nine",
"Zero"
}
local function Scan(location : any)
for i,v in pairs(location:GetChildren()) do
if v:IsA("Tool") then
table.insert(Items, v)
end
end
end
function update()
-- setting up preferred order
attempts += 1
if attempts == 1 then
for i, v in pairs(Items) do
table.insert(PreferredOrder, v)
end
end
-- clearing old frames
for i, v in pairs(Frames) do
v:Destroy()
table.remove(Frames, i)
end
-- setting up new frames
for i, v in pairs(Items) do
local new = template:Clone()
local values = v:WaitForChild("BackpackValues")
local color : Color3Value = values.color
local stroke : Color3Value = values.stroke
new.Parent = script.Parent
new.Name = v.Name
new.nameText.Text = v.Name
new.BackgroundColor3 = color.Value
new.UIStroke.Color = stroke.Value
new.bindText.Text = i
new.LayoutOrder = i
new.Visible = true
table.insert(Frames, new)
if equipped ~= nil and equipped == v then
new.UIStroke.Color = Color3.fromRGB(0, 255, 255)
end
new.MouseButton1Click:Connect(function()
if equipped ~= v then
equipped = v
hum:EquipTool(v)
if v:FindFirstChild(v.Name .. "UI") then
v[v.Name .. "UI"].Parent = player.PlayerGui
end
else
hum:UnequipTools()
equipped = nil
if player.PlayerGui:FindFirstChild(v.Name .. "UI") then
player.PlayerGui[v.Name .. "UI"].Parent = v
end
end
end)
uis.InputBegan:Connect(function(input, gpe)
if gpe then return end
if input.KeyCode == Enum.KeyCode[NumberKeycodes[i]] then
if equipped ~= v then
equipped = v
hum:EquipTool(v)
if v:FindFirstChild(v.Name .. "UI") then
v[v.Name .. "UI"].Parent = player.PlayerGui
end
else
hum:UnequipTools()
equipped = nil
if player.PlayerGui:FindFirstChild(v.Name .. "UI") then
player.PlayerGui[v.Name .. "UI"].Parent = v
end
end
end
end)
end
-- testing
print("Current Item Equipped:", equipped)
print("Function 'update()' attempt:", attempts)
print("Preferred Order of Items:", PreferredOrder)
print("List of Items:", Items)
print("UI Frames created for Items:", Frames)
end
function changed()
Items = {}
Scan(backpack)
Scan(char)
update()
end
changed()
--backpack.ChildAdded:Connect(changed)
--backpack.ChildRemoved:Connect(changed)
--char.ChildAdded:Connect(changed)
--char.ChildRemoved:Connect(changed)
player.CharacterAdded:Connect(function(char)
changed()
end)
Any help is appreciated!