How to showcase information on a Player's Screen GUI whenever a tool is equipped?

I wrote an ID card script that showcases a Player’s Username, Role, ID, and profile picture.

How do I get the script to showcase said information on the ID Card on the Player’s Screen GUI?

Script:


local handle = script.Parent.Handle
local SGUI = handle.SurfaceGui
local ScreenGUI = handle.ScreenGui.Frame

local lastupdated = 0

updateremote.OnServerEvent:Connect(function(player)
	if (tick() - lastupdated) >= 1 then
		lastupdated = tick()
		
		----------------------------------------------------------Surface GUI
		
		SGUI["SGUI Username"].Text = tostring(player.Name)
		SGUI["SGUI ID Number"].Text = tostring(player.UserId)
		local thumbnailtype = Enum.ThumbnailType.HeadShot
		local thumbnailsize = Enum.ThumbnailSize.Size420x420
		local picture = game.Players:GetUserThumbnailAsync(player.UserId, thumbnailtype, thumbnailsize)
		
		SGUI["SGUI Icon"].Image = picture
		
		---------------------------------------------------------Screen Gui
		ScreenGUI["Screen Icon"].Image = picture
		ScreenGUI["Screen ID Number"].Text = tostring(player.UserId)
		ScreenGUI["Screen Username"].Text = tostring(player.Name)
		

	end
end)

Local Script


local lastupdated = 0

script.Parent.Equipped:Connect(function()
	if (tick() - lastupdated) >= 1 then
		lastupdated = tick()
		
		updateremote:FireServer()
	end
end)

script.Parent.Equipped:Connect(function(player)
	player.LocalPlayer():WaitForChild("PlayerGUI")
	local plrGUI = player.PlayerGUI
	
	
	
end)
3 Likes

why do you need a remote event for just displaying the user info in a screen gui? you do not need to edit it in the server; instead you can just do

local LastUpdated = os.clock()

script.Parent.Equipped:Connect(function(player: Player)
    if (os.clock() - LastUpdated) > 1 then
        LastUpdated = os.clock()

        local PlayerGui = player.PlayerGui

        -- ... do the info screen gui showcase as usual
    end
end)
3 Likes

I do not quite understand how to get get the information on the ID card be displayed on a Player’s Gui when equipped.

3 Likes

its just the same thing as


		local thumbnailtype = Enum.ThumbnailType.HeadShot
		local thumbnailsize = Enum.ThumbnailSize.Size420x420
		local picture = game.Players:GetUserThumbnailAsync(player.UserId, thumbnailtype, thumbnailsize)
				
		---------------------------------------------------------Screen Gui
		ScreenGUI["Screen Icon"].Image = picture
		ScreenGUI["Screen ID Number"].Text = tostring(player.UserId)
		ScreenGUI["Screen Username"].Text = tostring(player.Name)
2 Likes

I cant seem to get it to work…how can I access PlayerGUI? The script and local script are both in the tool, whenever its equipped, an error message states " PlayerGui is not a valid member of Mouse “Instance” "

2 Likes

sorry, i thought the parameter in .Equipped were the player. Instead, you can get it by getting the localplayer, then getting the player gui:

local LocalPlayer = game.Players.LocalPlayer


local PlayerGui = LocalPlayer.PlayerGui
2 Likes

:WaitForChild() returns an instance, you don’t need to wait for child the playerGui then define it later, also if the player can equip tools their Gui has surely loaded already

You can’t change a player’s ScreenGui from the server

also the last updated part of the server script may cause problems with multiple players, if two equip the tool at the same the script will denounce and not change the badge of the second player.

1 Like

Correct me if I am wrong. The Player’s screen GUI is client sided and can only be manipulated using a Local Script. And the ID Card tool displays the player’s information server sided, which is manipulated using Server Script.

In order to get the ID Card Tool to display the player’s information, I have to have a function that detects the player and gathers their information, storing them in the Server Script.

This is the part where I am completely lost:
What must I do in order to get the player’s Screen Gui to display their ID Card’s GUI?

Context: I was following a tutorial on how to make an ID Card, but it did not showcase how to display said ID Card on the Player’s Screen Gui.

1 Like

You change the Client’s screen Gui thro the local script and fire the event to change the SurfaceGui.

also you may be able to set the data when the tool is given to the player instead if you don’t have data that might change during the game

1 Like

The data I am setting to the tool are Userid, Name, Profile Picture.

1 Like

Then you can probably set the information once, set the information at the beginning of a local script and just have it toggle the Gui when it is equipped/unequipped

For the server if it’s given through a function then you can set it in the function, if it’s on starter pack then in CharacterAdded event do a ```:WaitForChild()" and then set it there

2 Likes

You can change (most, if not all) properties server sided on PlayerGui and its children and descendants. Just keep in mind the client’s changes will not be replicated. Additionally, if I have a Frame that is red on the client, but green on the server, and the server sets the color to green again, it will not replicate and .Changed will not fire on either side. To workaround that if you need to, just set the color to some color you will never use the line before, then set it to whatever color you want (this is for the server btw).

That being said, never handle everything in PlayerGui on the server, it’s best used when you need to change something quickly without a remote event.

1 Like

A remote event will send client sided information to server?

1 Like

Well in this case, you don’t need a remote or a localscript at all. On tool equip on the server, you can find the character by script.Parent.Parent, then get the player with

game:GetService(“Players”):GetPlayerFromLocalPlayer(script.Parent)

Then get the PlayerGui, waitforchild on the ScreenGui (which actually should get moved to server parenting for safety) then finally set the properties.

1 Like

You mean this function?

So basically I should store all the data such as the player’s username, Id, and profile picture at the start of ServerScript. Then have both the Player’s Screen GUI and Tool Gui be scripted into the ServerScript?

1 Like

Yeah in your case do everything on the server.

1 Like

But keep the quoted script in the local script?

1 Like

Nah it’s best to do it on the server.

1 Like

Is the server tick function even necessary?

I’d cut that out sorry for the lack of clarity.
For equipped:

local screenGui = script.Parent.ScreenGui
tool.Unequipped:Connect(function()
screenGui.Parent = script.Parent
end)
tool.Equipped:Connect(function()
local character = script.Parent.Parent
local player = game:GetService(“Players”):GetPlayerFromCharacter(character)
if not player then return end
screenGui.Parent = player.PlayerGui
--now just treat it as a normal screen gui and set properties that need to be set
end)

Sorry I’m on mobile. This only includes what you need for screenGui not surface.