Enum KeyCodes Not Working (ServerScript) [OverheadGUI Frame Visibility Toggle Script]

Greetings, thank you for clicking this.

I’m mainly a builder but I can do basic scripts / UI Designs, I’m kind of new to scripting so please consider that while answering.

I’m trying to add a Visibility Toggle Key to a current-working Overhead GUI script. That means I’m expecting this script to work as the following:

If I press a certain key, it would show/hide the Overhead GUI displaying the rank.

It doesn’t work from game:GetService("UserInputService").InputBegan:Connect(function(key), the ones upper than that works fine. Sorry for the long script.

local billboardgui = game:GetService("ServerStorage"):WaitForChild("OverheadGui")

game.Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(character)
		local clonedgui = billboardgui:Clone()
		local PlayerRank = Player:GetRoleInGroup(8551076)
		clonedgui.Frame.TextLabel.Text = PlayerRank

		if Player.Team == game.Teams.Jedi then		
			clonedgui.Frame.TextLabel.TextColor3 = Color3.fromRGB(13, 105, 172)
			clonedgui.Frame.TextLabel.Text = "Hostile"
			clonedgui.Parent = game.Workspace:WaitForChild(Player.Name).Head

		elseif Player.Team == game.Teams.Sith then
			clonedgui.Frame.TextLabel.TextColor3 = Color3.fromRGB(151, 0, 0)
			clonedgui.Parent = game.Workspace:WaitForChild(Player.Name).Head

		elseif Player.Team == game.Teams.Visitor then
			clonedgui.Frame.TextLabel.TextColor3 = Color3.fromRGB(39, 70, 45)
			clonedgui.Parent = game.Workspace:WaitForChild(Player.Name).Head

		elseif Player.Team == game.Teams["Temple Guard"] then
			clonedgui.Frame.TextLabel.TextColor3 = Color3.fromRGB(239, 184, 56)
			clonedgui.Frame.TextLabel.Text = Player:GetRoleInGroup(8113831)
			clonedgui.Parent = game.Workspace:WaitForChild(Player.Name).Head

		elseif Player.Team == game.Teams["Jedi Council"] then
			clonedgui.Frame.TextLabel.TextColor3 = Color3.fromRGB(0, 32, 96)
			clonedgui.Parent = game.Workspace:WaitForChild(Player.Name).Head

		else

			clonedgui.Parent = game.Workspace:WaitForChild(Player.Name).Head

		end

		game:GetService("UserInputService").InputBegan:Connect(function(key)
			if key.KeyCode == Enum.KeyCode.V then
				if clonedgui.Frame.Visible == true then
					clonedgui.Frame.Visible = false
				else
					clonedgui.Frame.Visible = true
				end
			end
		end)
	end)
end)                

Now, how would I make this work as it does not work?

1 Like

Enum Keycode can only be used in client sided as userinput can only be client side.

1 Like

Oh, okay. Is there a way to make it work, then?

Do you want the overhead GUI visible to certain clients?

1 Like

No, I want the script to make the key a toggle to make it visible/hidden for everyone.

Ah,interesting. What you can do is put UIS in local script, put the local script at StarterPlayer and Create a remote event inside replicated storage. That will needed for the client server communication

localscript:

local UIS = game:GetService("UserInputService")
local Remotes = game:GetService("ReplicatedStorage"):WaitForChild("YourRemoteName")

UIS.InputBegan:Connect(function(Input) --The parameter can be whatever
    if Input.Keycode == Enum.Keycode.V then --if input equals to V
        Remotes:FireServer() --Fire remote to the server
    end
end)

ServerScript

--Add this and replace the line of the server UserInputService

local Remotes = game:GetService("ReplicatedStorage"):WaitForChild("YourRemoteName")

Remotes.OnServerEvent:Connect(function(player) --First param is player that fires the remote
    clonedgui.Frame.Visible = not clonedgui.Frame.Visible
end
1 Like

Thank you so much.

However, this doesn’t work, the Output says:

- Keycode is not a valid member of InputObject "InputObject"  

Did I do something wrong?

ah yes, i mustve typo. Change it to KeyCode. Apologies for that

1 Like

THANK YOU!

This WORKED!

Also I also recognized another typo in the last line of the ServerScript:

That one has to be changed to “end)”. Thank you so much.

For the ones viewing this in the future, the final script is:

LocalScript:

local UIS = game:GetService("UserInputService")
local Remotes = game:GetService("ReplicatedStorage"):WaitForChild("YourRemoteName")

UIS.InputBegan:Connect(function(Input) --The parameter can be whatever
    if Input.KeyCode == Enum.KeyCode.V then --if input equals to V
        Remotes:FireServer() --Fire remote to the server
    end
end)

ServerScript:

--Add this and replace the line of the server UserInputService

local Remotes = game:GetService("ReplicatedStorage"):WaitForChild("YourRemoteName")

Remotes.OnServerEvent:Connect(function(player) --First param is player that fires the remote
    clonedgui.Frame.Visible = not clonedgui.Frame.Visible
end)

All credits to @ikanbuntal12 <3

Oh also, I just realized that that script toggles all users’ Overhead GUI to appear/disappear. Is there a way to make it show/hide the Overhead GUI of the user who presses the Key only FROM everyone? If you didn’t understand, I can explain more.

ah, you put the word super confusing but thats okay. Just remove the remote and set ovehead GUI invisible through client

1 Like

How would I do that ‘through client’? Again, I’m a bit new to scripting.

It hides or shows the entire user’s OverheadGUI in the server, but I want it to hide or show only that user’s GUI, and I want that user’s GUI to appear/disappear from everybody but the other’s GUI shouldn’t disappear together.

So this can’t be in a local script.

scripts run on the server, meaning whatever is executed in them happens to the whole server
local scripts on the other hand run just for one player.

now what you are going to want to do is run the user input service on a local script to detect when one person puts their key down.

when that person puts their keydown i believe you want it to hide the GUI above their head? so you will fire an event to the server telling it to get rid of the gui above the player that pressed the key?

i will explain this in more depth if this sounds about right to what you are tring to achieve.

1 Like

Yes, that’s what I’m trying to do.

alright so what you want to do is go into the explorer. go down to starterplayer>starterplayerscripts and right click it. “click insert” object then click “localplayer script”

when you have done this ill tell you how to set up the scripts and events and if you get stuck with anything i see feel free to ask

1 Like

Alright thanks, I know how to set up local scripts :slight_smile:

By the way the thing is that while I want the script to remove that player’s GUI from everyone, it removes EVERYONE’S Overhead GUI.

(Yes, I know how to set up local scripts so no need to be so step-by-step.)

alright sorry i just wasnt sure how familiar you were with things and just to clarifiy

you want this to hide the GUI above that one individual that presses the button so no one else can see it?

1 Like

Mhm, yes. I want it to make it back visible if it’s currently invisible and you press back V, by the way.

yes thats fine so now moving on.
put a “RemoveEvent” into the replicated storage

and also upload the latest version of the script we are working with because im not sure how its changed since your original post

1 Like

Alright, already done that. The RemoteEvent’s name is “VisibilityEvent”