Custom Hotbar Glitch

THIS IS SOLVED PLEASE IGNORE THE POST , I DON’T KNOW HOW TO PRIVATE IT

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    My Hotbar system doesn’t work correctly and i wanted it to. I spent like 7 hours fixing this glitch , Nothing worked and it is driving me crazy

While i am working on adding new tool , This glitch start to happen. I’ve been using hotbar code i made like 1 year ago in which i don’t even know what is in the script anymore (it is also messy) so i write a whole new code expecting to fix the problem but it got worse.

  1. What is the issue? Include screenshots / videos if possible!
    Expected Behavior :
    -Selecting empty hotbar slot will automatically equip default tool (In this case it “Fist”)
    -Picking up item when an empty hotbar slot is selected would put the newly picked up item into that empty hotbar slot
    -Picking up item when the selected hotbar slot has item in it will put the item in earliest empty hotbar slot

Current Behavior :
My explaination is quite bad sorry for that. For test project go here : Hotbar Glitch pls help - Roblox (Computer required)
-Control :
X - drop
E - pickup item

(Below is a bunch of yapping , skip if you want. Go to the test place instead)
I don’t even know how to explain this…
When you drop an item then picking it up , it work just fine ONLY if it is in the first hotbar slot.
But it start glitching out if it wasn’t picked up and put in the first hotbar slot.
After picking up item in any hotbar slot but the first slot , Item would enter player character (and into selected slot) Which is expected BUT when i switch to different slot , the slot kind of replicate itself to the new empty slot you select , Only happen once. And selecting any occupied hotbar slot that isnt the first slot will replicate it to the first slot.

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I don’t even know anymore , i tried almost everything and nothing worked

my explaination is pretty bad so you can ask me for more any specific things.

------Code
-OrderTable is used as hotkey slot for items
-There are tons of commented line , please ignore them
-Function UpdateBar() is for visual , ignore it

The hotkey code :


task.wait(0.5)
local UIP = game:GetService("UserInputService")

local Plr = game.Players.LocalPlayer
local PChar = Plr.Character or Plr.CharacterAdded:Wait()
local PHum = PChar:WaitForChild("Humanoid")
local PRoot = PChar:WaitForChild("HumanoidRootPart")


local Main = game.Workspace:WaitForChild("Main")

local DefaultN = "Fist"
local DefaultTool = PInv:WaitForChild(DefaultN)
local OrderTable = {}

local ToolWork = PChar.Data.System.ToolWork

local GameRule = game.ReplicatedStorage:WaitForChild("Rule")

local GameplayGUI = game.Players.LocalPlayer.PlayerGui:WaitForChild("Gameplay")



local ItList = GameplayGUI.Main.Right.ItemList
local InvGUI = {ItList.Slot1,ItList.Slot2,ItList.Slot3,ItList.Slot4,ItList.Slot5,ItList.Slot6,ItList.Slot7,ItList.Slot8,ItList.Slot9,ItList.Slot10}

local CSlot = 1--Tool Slot that player is Holding 
local KeyPressOrder  --Key pressed in order

game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.PlayerList, false)
game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Health, false)
game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, false)

local AllKey = {
	Enum.KeyCode.One,
	Enum.KeyCode.Two,
	Enum.KeyCode.Three,
	Enum.KeyCode.Four,
	Enum.KeyCode.Five,
	Enum.KeyCode.Six,
	Enum.KeyCode.Seven,
	Enum.KeyCode.Eight,
	Enum.KeyCode.Nine,
	Enum.KeyCode.Zero
}







function UpdateBar(InInv)
	--print(OrderTable)
	
	for i = 1,10 do
		local Frame = InvGUI[i]
		local Item = OrderTable[i]
		
		if Item then
			Frame.ItemName.Text = string.upper(Item.Name)
		else
			Frame.ItemName.Text = "NONE"
		end
		
		if i == CSlot then
			InvGUI[i].ItemName.TextColor3 = Color3.fromRGB(190,255,190)
			InvGUI[i].BackgroundColor3 = Color3.fromRGB(80,120,80)
			InvGUI[i].BorderColor3 = Color3.fromRGB(50,255,50)
		else
			InvGUI[i].ItemName.TextColor3 = Color3.fromRGB(255,255,255)
			InvGUI[i].BackgroundColor3 = Color3.fromRGB(0,0,0)
			InvGUI[i].BorderColor3 = Color3.fromRGB(255,255,255)
		end
	end
	--print(OrderTable)
end















function ToolSwitch(Key,gs)
	if gs or ToolWork.Value >= 1 or GameRule.AllowTool.Value <= 0 or PChar.Data.State.Stunned.Value >= 1 then
		return
	end
	
	local KIndex = table.find(AllKey,Key.KeyCode)
	if KIndex then
		CSlot = KIndex
		print("CSlot : ",CSlot)
		PHum:UnequipTools()
		if OrderTable[KIndex] == nil then
			PHum:EquipTool(DefaultTool)
		else
			PHum:EquipTool(OrderTable[KIndex])
		end
		UpdateBar()
		
	elseif Key.KeyCode == Enum.KeyCode.X then
		local ToolFind = PChar:FindFirstChildOfClass("Tool")
		if ToolFind then

			if ToolWork.Value <= 0 and ToolFind.Data.CanDrop.Value == true and PChar.Data.State.Stunned.Value <= 0 then

				local UVec = (PRoot.CFrame.LookVector)*7
				local RayParam = RaycastParams.new()
				RayParam.FilterDescendantsInstances = {Main.Enemy,Main.Corpse,Main.Proxy,Main.Item}
				RayParam.FilterType = Enum.RaycastFilterType.Exclude
				local Rayy = game.Workspace:Raycast(PRoot.Position,UVec,RayParam)

				local DropPos
				if Rayy then
					if Rayy.Magnitude >= 2.5 then
						DropPos = PRoot.Position + (PRoot.CFrame.LookVector*(Rayy.Magnitude-2))
					end
				else
					DropPos = PRoot.Position + PRoot.CFrame.LookVector*5
				end

				if DropPos then
					--Drop item
					ToolFind.Parent = Main.ItemAlt
					ToolFind.Handle.CFrame = CFrame.new(DropPos)
					ToolFind.Handle.Anchored = true
					game.ReplicatedStorage.Remote.System.DropItem:FireServer(ToolFind,DropPos)
					
					PHum:UnequipTools()
					
					PHum:EquipTool(DefaultTool)
					--UpdateBar()
					--ToolFind.Main.Hitbox.CanCollide = true
				--[[local ToolFind = game.ServerStorage.Items:FindFirstChild(Item.Name)
				if ToolFind then
				end]]
					--print(PRoot.Position)
					--print(DropPos)

					--[[
					local It = time()
					repeat
						ToolFind.Main.PrimaryPart.CFrame = CFrame.new(DropPos)
						task.wait(0.01)
					until It+4 < time()]]
					--ToolFind.Main.PrimaryPart.CFrame = CFrame.new(DropPos)
					--ToolFind.Parent = workspace --Main.Item
					--ToolFind.Handle.CFrame = CFrame.new(DropPos)
				end
			end
		end
	end
end
UIP.InputBegan:Connect(ToolSwitch)


function NewTool(Tool,Topper)
	
	if Tool:IsA("Tool") and not (Tool.Name == DefaultN) then
		
		if not table.find(OrderTable,Tool) then
			warn("New Tool Added")
			local PosAdd = 99
			if OrderTable[CSlot] == nil then -- Topper == nil
				PosAdd = CSlot
			else
				for i=1,10 do
					if OrderTable[i] == nil then
						PosAdd = i
						break
					end
				end
			end
			--table.remove(OrderTable,PosAdd)
			--table.insert(OrderTable,PosAdd,Tool)
			OrderTable[PosAdd] = Tool
			UpdateBar()
			
			
			local Conn
			Conn = Tool:GetPropertyChangedSignal("Parent"):Connect(function()
				if not (Tool.Parent == Plr.Backpack or Tool.Parent == PChar) then
					print("Bfo",OrderTable)
					local Poss = table.find(OrderTable,Tool)
					--table.remove(OrderTable,Poss)
					--table.insert(OrderTable,Poss,nil)
					--if Poss or true then
						
					--end
					print("Old  ",OrderTable[PosAdd])
					OrderTable[PosAdd] = nil
					--OrderTable[PosAdd] = nil --table.find(OrderTable,Tool)
					UpdateBar()
					print("WIPEDDDDDDDDDDDDDDDDd")
					--print(OrderTable)
					Conn:Disconnect()
				end
			end)
		end
	end
end
PChar.ChildAdded:Connect(NewTool)
Plr.Backpack.ChildAdded:Connect(function(ch)
	NewTool(ch,true)
end)




RemoteFolder.####.OnClientEvent:Connect(function(Item)
	if Item then
		if Item:FindFirstChild("Handle") then
			Item.Handle.Anchored = false
		end
	end
end)

I will not reply for the next 8-10 hours after this post. I need to sleep.

I highly appreciate everyone for helping me out. It probably going to take a long time for you to figure it out.

1 Like

I added 2 short line of code and it worked… somehow

i am never going to touch this code ever again after this