This commandbar is not properly executing?

some reason this commandbar when i use the commandbar and try executing a command from it, it doesn’t work when pressing enter it doesn’t even erase what was added as it says it would so i’m assuming it’s that part that isn’t right? or is it the way it’s being executing not right? if anyone leads me in the right direction i’ll be fine. i just don’t understand what’s wrong like why is it not letting me execute the commands when i press the enter key?

local function createCommandBar(player)
	local cmdbarGui = Instance.new("ScreenGui")
	cmdbarGui.Name = "CommandBarGui"
	cmdbarGui.Parent = player.PlayerGui

	local cmdbarFrame = Instance.new("Frame")
	cmdbarFrame.Name = "CommandBarFrame"
	cmdbarFrame.Size = UDim2.new(0.5, 0, 0.5, 0)
	cmdbarFrame.Position = UDim2.new(0.25, 0, 0.25, 0)
	cmdbarFrame.BackgroundTransparency = 0.5
	cmdbarFrame.BackgroundColor3 = Color3.new(0, 0, 0)
	cmdbarFrame.Parent = cmdbarGui

	local cmdbarList = Instance.new("ScrollingFrame")
	cmdbarList.Name = "CommandBarList"
	cmdbarList.Size = UDim2.new(1, 0, 0.9, 0)
	cmdbarList.Position = UDim2.new(0, 0, 0, 0)
	cmdbarList.BackgroundTransparency = 0.5
	cmdbarList.BackgroundColor3 = Color3.new(1, 1, 1)
	cmdbarList.Parent = cmdbarFrame

	for i, cmdName in ipairs(commands) do
		local cmdLabel = Instance.new("TextLabel")
		cmdLabel.Size = UDim2.new(1, 0, 0, 20)
		cmdLabel.Position = UDim2.new(0, 0, 0, (i - 1) * 20)
		cmdLabel.Text = prefix .. cmdName
		cmdLabel.TextColor3 = Color3.new(0, 0, 0)
		cmdLabel.BackgroundTransparency = 1
		cmdLabel.Parent = cmdbarList
	end

	local cmdbarInput = Instance.new("TextBox")
	cmdbarInput.Size = UDim2.new(1, 0, 0.1, 0)
	cmdbarInput.Position = UDim2.new(0, 0, 0.9, 0)
	cmdbarInput.TextColor3 = Color3.new(0, 0, 0)
	cmdbarInput.BackgroundTransparency = 0.5
	cmdbarInput.BackgroundColor3 = Color3.new(1, 1, 1)
	cmdbarInput.Parent = cmdbarFrame

	-- Send the command to the chat when Enter key is pressed
	cmdbarInput.Focused:Connect(function()
		cmdbarInput.FocusLost:Connect(function(enterPressed)
			if enterPressed then
				local inputText = cmdbarInput.Text
				if inputText:sub(1, #prefix) == prefix then
					local commandName = inputText:sub(#prefix + 1)
					for _, cmdData in ipairs(commands) do
						if cmdData.name == commandName then
							cmdData.action(player, {})
							break
						end
					end
				end
				cmdbarInput.Text = ""  -- Clear the input after sending the command
			end
		end)
	end)
end


-- Add more commands using the addCommand function

addCommand("cmdbar", "admin", function(player, args)
	local existingGui = player.PlayerGui:FindFirstChild("CommandBarGui")
	if not existingGui then
		createCommandBar(player)
	else
		existingGui:Destroy()
	end
end)```
1 Like

i’m assuming it’s cause the code is running before i press the enter key, or it’s not implemented correctly. but not sure

1 Like

i think it’s cause it’s client sided execution. trying now