Event not firing

Hey there! I’m making an admin bar based off Basic Admin. I’ve ran into an issue though. The event doesn’t fire even with the correct command. Any help would be greatly appreciated.

Problem snippet:

local function onGuiInputEntered(input)
	if input and typeof(input) == "userdata" and input.UserInputType == Enum.UserInputType.Keyboard and input.KeyCode == Enum.KeyCode.Return then
		if frame.Text == "uniform" then
			-- Fire the remote event if the player typed "/uniform"
			frame.Text = "TEST"
			uniformEvent:FireServer(player)

		end

		-- Clear the text in the GUI and hide it
		frame.Text = ""

		tweenGuiFrame(initialSize)

		isGuiVisible = false

		print("command bar closed")
	end
end

FULL

-- We must get the UserInputService before we can use it
local UserInputService = game:GetService("UserInputService")

-- Define the GUI frame and its initial and final sizes
local frame = script.Parent.TextBox
local initialSize = UDim2.new(1, 0, 0, 0)
local finalSize = UDim2.new(1, 0, 0.1, 0)
local player = game.Players.LocalPlayer
-- Define the duration, easing style, and easing direction of the tween
local tweenDuration = 0.09
local easingStyle = Enum.EasingStyle.Sine
local easingDirection = Enum.EasingDirection.In

-- Define the TweenInfo object that will be used by the TweenService
local tweenInfo = TweenInfo.new(tweenDuration, easingStyle, easingDirection)

-- Define a variable to keep track of whether the GUI is currently visible
local isGuiVisible = false

-- Define the remote event to fire when the player types "/uniform"
local uniformEvent = game.ReplicatedStorage.RemoteEvent

-- A function to tween the GUI frame to the specified size
local function tweenGuiFrame(size)
	local propertiesToTween = {
		Size = size
	}
	local tween = game:GetService("TweenService"):Create(frame, tweenInfo, propertiesToTween)
	tween:Play()
end


local function onGuiInputEntered(input)
	if input and typeof(input) == "userdata" and input.UserInputType == Enum.UserInputType.Keyboard and input.KeyCode == Enum.KeyCode.Return then
		if frame.Text == "uniform" then
			-- Fire the remote event if the player typed "/uniform"
			frame.Text = "TEST"
			uniformEvent:FireServer(player)

		end

		-- Clear the text in the GUI and hide it
		frame.Text = ""

		tweenGuiFrame(initialSize)

		isGuiVisible = false

		print("command bar closed")
	end
end


-- A function to handle player input outside the GUI
local function onInputBegan(input, gameProcessed)
	if input.KeyCode == Enum.KeyCode.Quote then
		if isGuiVisible then
			-- If the GUI is currently visible, tween it to its initial size and hide it
			tweenGuiFrame(initialSize)
			frame.Text = ""
			isGuiVisible = false
				print("command bar closed")
				
		else
			-- If the GUI is currently hidden, tween it to its final size and show it
			tweenGuiFrame(finalSize)
			isGuiVisible = true
			frame.Text = "Enter a command."
			print("command bar opened")
		end
	end
end

-- Connect the onGuiInputEntered function to the InputBegan event of the GUI
frame.FocusLost:Connect(onGuiInputEntered)

-- Connect the onInputBegan function to the InputBegan event of the UserInputService
UserInputService.InputBegan:Connect(onInputBegan)

Any help would be great, as my scripting skills are pretty lack luster.

In the FULL script you’ve shown it defines the uniformEvent but there is no code connecting that event to the function you want to run when it is actually fired to the server. Also in the code that is doing uniformEvent:FireServer(player) you don’t need the player parameter as it is automatically added.

You could add this as a placeholder to see if it is firing:

uniformEvent.OnServerEvent:Connect(function(player)
	print(player .. " just fired the event!")
end)
1 Like

It doesn’t seem like the event is firing. I added the suggestions and it fails to print anything in the output via the server.

I don’t believe your function onGuiInputEntered is set up correctly. It is actually being called but the “input” it receives is a boolean because it is connected to FocusLost so it fails your condition of the typeof(input) being “userdata”.

Maybe you want it like this??:

local function onGuiInputEntered(input)
	if frame.Text == "uniform" then
		-- Fire the remote event if the player typed "/uniform"
		frame.Text = "TEST"
		uniformEvent:FireServer(player)

	end
end
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.