How would I make a GUI visible only to Certain Players

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!
    (Apologies If this topic might be confusing, but I explained the best I can)
    Hello I’am New to Coding on Roblox and I’am currently working on an RPG battle system and I’am having a bit of a roadblock.
    So the basic Idea of what i’am trying to do is have a system where whenever a Player in a Battle Uses A Spell or Skill, the Name of that Spell/Skill will Appear’s Based on the (As show in the Picture)

  2. What is the issue? Include screenshots / videos if possible!

What I’am having trouble with is finding a way to have it so that other Players other than the Person who uses the skill/spell are able to see the GUI as well depending on what their Number Values (I.E if any player’s NumberValues are 1-4 than only those players can See the GUI)

I’am able to have it so that the Player who Use the skill/spell is able to see it’s GUI but I can only do it with a local script and as a result other player’s are not able to see the window themselves

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

I’ve tried using a regular script but I’am not able to get the LocalPlayer, I’ve also tried (or attempted) to use a RemoteEvent and although I was able to get the LocalPlayer, The game was not able to detect/find the NumberValue inside the Player
image

I’ve tried searching topics to see if i can get a lead on what I should do but i’m pretty much lost on how I should go about doing this.

5 Likes

Hey! Maybe this post can help!

2 Likes

Heres some localscript I made so only a certain player can view it.

local players = game.Players.LocalPlayer
local gui = script.Parent.Frame -- location of the ui

if players.Name == "DrxpLoxs" then
gui.Visible=true
else
print("User is not me, gui hidden")
end

Can also do it by user ID to.

local users = {1234567, 123467} --userids
local gui = script.Parent.Frame
local players = game.Players.LocalPlayer

for _, user in pairs (users) do
      if (user== players.UserId) then
            gui.Visible= true
      end
end
8 Likes

Why are you trying to iterate through a gui object? First of all that will error. You need a table to iterate through, but even logically the code won’t work. What you are defining in script.Parent.Frame is a frame, not a gui. A frame does not have an Enabled property. Just Visible.

for _, user in pairs (users) do
      if (user == player.UserId) then
            frame.Visible = true
      end
end

Basically we just iterate through the ids, check if one of them matches the player’s, if so we do something such as in this case we make the frame visible.

I am not sure if the replies above are relevant to what you asked for, the thread is a little bit confusing. Could you explain exactly what you are trying to do in simple words again?

Ah…Apologies.
So the basic Idea of what im trying to do: I’am trying to make it so that when a player Uses a skill/or Spell, the name of the Said skill/spell will appear on top of the screen In a GUI.

So for example In my game, If Player1 were to press 1 to use a Spell name ‘Flame Stone’, A GUI will appear on the screen that Says "Flame Stone’.


What I’am trying to do is have it so that certain other players can see the GUI that says ‘Flame Stone’ and not Just Player1 .

You can use a remoteevent to fire the server and from the server fireallclients.
And handle the OnClientEvent to disaplay the GUI.

I actually have tried using a RemoteEvent, when I use a RemoteEvent the game for some reason thinks that the Value that is in the Local Player (PartyMemberNum) is not persent

image

(Or at least that what it looks like to me)

Which is essential because this is what I’am Using to determine who gets to see the GUI

How did you create the PartyMemberNum?

I have a Local Script in StarterPlayerScripts that creates PartyMemberNum the Instant a player joins

local plr = game.Players.LocalPlayer

local PartyMemberNum = Instance.new("NumberValue")
PartyMemberNum.Parent = plr
PartyMemberNum.Name = "PartyMemberNum"
PartyMemberNum.Value = 0


You either have to do it from the server or use remoteevent or use ‘Script’ to create the NumberValue otherwise the server will not see it. Creating something from localscript is only visible to the client not the server due to filteringEnabled.

Okay I’ve managed to make a RemoteEvent for creating the NumberValue, However I can seem to be able to get the GUI to TweenPosition from fire’ing from the RemoteEvent however.

--<Services>--
local ReplicatedStorage = game:GetService("ReplicatedStorage")
--<FlameStone GUI Event>--
local RemoteFlameStone = game.ReplicatedStorage.SkillSpellGui.Mage.FlameStone
Open = false
RemoteFlameStone.OnServerEvent:Connect(function(plr)
	local BattlePlacement = plr.PartyMemberNum
local	gui = plr.PlayerGui.BattleExclusiveGUI.CastingSet.StarWaveSpell.StarWaveGui
local box = gui.box

	if BattlePlacement.Value == 1 or BattlePlacement.Value == 2 or BattlePlacement.Value == 3 or BattlePlacement.Value == 4 then
		
			local frame = plr.PlayerGui.BattleExclusiveGUI.CastingSet.StarWaveSpell.StarWaveGui.box
			frame:TweenPosition(UDim2.new (0.271, 0,0.020,0) )
			box.Visible = true
			
			Open = true
			wait (1.8)
			frame:TweenPosition(UDim2.new (0.271, 0,-0.210,0) )
			wait (1)
			box.Visible = false	
	else
		
		end
end)

I’am still new at Using RemoteEvents and I’am Unsure what i’am doing wrong here.

This will only display the Gui on the player who fired the remoteevent, others will not be able to see it.

Oh? Why would this be the case?
(Just out of curiosity)

Every client has their own gui because of that you need to go through every player and make it visible. And using loop can cause delay therefore you should use FireAllClients.

Example using your code

In ServerScriptService put this code inside a ‘Script

--<FlameStone GUI Event>--
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteFlameStone = ReplicatedStorage.SkillSpellGui.Mage.FlameStone

-- Handle Remote
RemoteFlameStone.OnServerEvent:Connect(function(plr)
	RemoteFlameStone:FireAllClients(plr.Name) -- send the player name
end)
--[[
-- example of crating PartyMemberNum from the server
game.Players.PlayerAdded:Connect(function(plr)	
	local PartyMemberNum = Instance.new("IntValue",plr)
	PartyMemberNum.Name = "PartyMemberNum";
	PartyMemberNum.Value = 0
end)
--]]

Put the following code inside the Gui in a localscript.

local plr = game:GetService("Players").LocalPlayer
local RemoteFlameStone = game.ReplicatedStorage.SkillSpellGui.Mage.FlameStone
local Open = false
-- Handle client event
RemoteFlameStone.OnClientEvent:Connect(function(playerName)
    print(playerName.." used FlameStone")
	local BattlePlacement = plr.PartyMemberNum
	local gui = plr.PlayerGui.BattleExclusiveGUI.CastingSet.StarWaveSpell.StarWaveGui
	local box = gui.box
		if BattlePlacement.Value >=1 and BattlePlacement.Value <= 4 then
			box:TweenPosition(UDim2.new (0.271, 0,0.020,0) )
			box.Visible = true			
			Open = true
			wait (1.8)
			box:TweenPosition(UDim2.new (0.271, 0,-0.210,0) )
			wait (1)
			box.Visible = false	
		else		
		end
end)

5 Likes

i once created something similar that would answer your question. it makes it to where the gui will be enabled if the playername matches. its a ScreenGui in StarterGui and it has a LocalScript inside of the ScreenGui that contains the following code:

if game.Players.LocalPlayer.Name == "Drewel112233" then --the player name
	script.Parent.Enabled = true --enables the gui; shows it on the players screen
else
	script.Parent.Enabled = false	--disables the gui; hides it from the players screen
end

note: this is for 1 player. if you want to you can add a table that has the player names you want like so:

local players = {"playername1","playername2"} --add more strings for more players

then the script would be like so:

local players = {"playername1","playername2"} --add more strings for more playernames
if game.Players.LocalPlayer.Name == #players then --gets all strings from the table "players", if the playername matches the name given in the table
	script.Parent.Enabled = true --enables the gui; shows it on the players screen
else
	script.Parent.Enabled = false	--disables the gui; hides it from the players screen
end

this should give you an example of how you can do this.

Your method is not preferred, as exploiters could easily just show the GUI.
This method is much better, as a Server Script in Server Script Service.

Let me know if this helps.

game.Players.PlayerAdded:Connect(function(player) --When Player Joins The Game
   if player.Name == USERNAME then  --If The Player Matches The Specified Username
        local newgui = game.ServerStorage.LOCATION_OF_GUI:Clone()  --Make A New Copy Of The GUI
        newgui.parent = game.Players:WaitForChild(player).PlayerGui --Give It To The Player
    end
end)
1 Like

Okay so good news is It is working


(Player 1)

(Player 2)

Bad news…


Upon using the spell the GUI is repeatidly looping and it’s causing the Player to lag hard to the point that the game is running at 2 FPS.

Edit: Fixed it, I added debounce to get it to stop.

2 Likes

I like this method best, as it is the easiest! Thanks for sharing.

1 Like