Roblox player has bug, studio does not

  1. 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.

  2. 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)

  3. 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:
image_2024-12-14_110108631

studio screenshot of gui (what it should look like):
image_2024-12-14_110209656

player screenshot 1(what I want to happen)
image_2024-12-14_110346687

player screenshot 2(what usually happens)
image_2024-12-14_110414016

-- 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!

6 Likes

Ok so, after making these changes you did do file → publish to roblox correct? Otherwise any changes you have made wont be in the actual game.

After that, in game, check the developer console to check for errors
(esc/menu thingy → settings → near the bottom theres developer console or something like that)

I take it something is probably just erroring and thats why its breaking, so check that!

4 Likes

yes, I have done all of those
I believe it is a roblox player bug

6 Likes

well are there any errors in the console?
I doubt its a roblox player bug.

Also check if the UI is visible and enabled, along with that put prints in the code to make sure it actually runs

(test all of these in game btw)

7 Likes

In the player there are bugs, however none of them affect the script that is “broken”

Studio runs fine, no errors
Ui is visible, tested with printing too

also just realized im using bloxstrap which might be the problem

6 Likes

You are not updating the backpack variable, and you need to do so because the backpack is destroyed each time the character respawns (including the first backpack when the player joins the game, it resets when the character spawns).

You also need to use WaitForChild for the backpack, as the character may respawn before the new backpack is created. Keep in mind that Roblox Studio and Roblox Player do not work the same, Roblox Player has more delay compared to Studio which may explain why it work on Roblox Studio and not on Roblox Player.

Also make sure to disable ResetOnSpawn propertie on your ScreenGui called BackPack, and change the char parameter to newChar on your CharacterAdded connection, otherwise the script won’t recognize what is the newChar and what is the current one.

local char : Model = player.Character or player.CharacterAdded:Wait()
local backpack : Backpack = player:WaitForChild("Backpack")
local hum : Humanoid = char:WaitForChild("Humanoid")
local animator : Animator = hum:WaitForChild("Animator")

local function UpdateCharacter(newChar)
    char : Model = newChar
    backpack : Backpack = player:WaitForChild("Backpack")
    hum : Humanoid = char:WaitForChild("Humanoid")
    animator : Animator = hum:WaitForChild("Animator")
end)

player.CharacterAdded:Connect(function(newChar)
    UpdateCharacter(newChar)
	changed()
end)
7 Likes

Ohh yes thats probably it!
I would also recommend enabling the char and backpack child added and remove events just incase the tools dont load in yet.

Somebody woke up on the wrong side of the bed

6 Likes

why is he so mad lmao
(character limit:sob:)

5 Likes

That is very interesting, thank you tho!

3 Likes

It looks like that fixed some of the bugs, however the UI still is randomly just not appearing
ex: The UI for 2 of my testing tools appeared, the other 3 did not

3 Likes

are you getting any errors in the console when playing in the Roblox player?

2 Likes

none related to the script thats broken

2 Likes

so i messed around with a couple of things and kinda sorta figured it out


basically the backpack works, like tools n stuff, but the frames and ui is VERY VERY broken in player

4 Likes