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?
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
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)
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 onlyFROM everyone? If you didn’t understand, I can explain more.
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.
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.
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