How would I make an imagebutton hidden to the local player only?

Hi there, I have a playerlist GUI with a friend request button. How would I make button hidden from the local player as the gui is in ReplicatedStorage and cloned to the scrolling frame of my GUI in StarterGui?

I don’t have an attempt since the GUI is cloned from ReplicatedStorage which I have no idea how to start from there.

Do you mean the ui that you made will be cloned to the client gui (PlayerGui)? Cause if in StarterGui, then no one will be able to see it.

I believe that your trying to make the client(player) not be able to view the friend request button to itself??

Yeah. This is a screenshot of the explorer to help you understand better.

Change the Visible property for that specific player using a LocalScript. You can achieve this using remotes, or changing a value on the server which is also visiible for that specific client. There are a lot ways to achieve it but the main idea is to force a client script to apply a local change at a specific moment.

Edit: if you want it to hide by default just do ImageButton.Visible = false from a client script before parenting the UI(or if the UI is in StarterGui set the value when the LocalScript starts).

How would I define the local player in a if scenario? I’m going to try and use if however, how would I do that with a variable that defines the local player?

Also the reason my solution didn’t work on the previous post was cause you renamed your TextLabel to name for it to work it has to be named PlayerName.

local Players = game:GetService("Players")
local Player = Players.LocalPlayer

print(Player.Name) 
1 Like

Yeah I noticed that, I’ll actually make that the solution since I solved it already to a issue relating to that.

1 Like

How do I do something like this then? I know the script is incorrect.

local players = game:GetService("Players")
local players2 = players.LocalPlayer

local gui = script.Parent.Parent.StarterGui.PlayerList.Frame.ScrollingFrame.Template.ImageButton

if players2 then
	gui.Visible = false
end

You don’t even have to use an if statement, if it’s a LocalScript the changes you make will always apply for that specific Player(basically the statement is always true).

Ohh, I understand now. But the thing is, is that multiple of these buttons are cloned of a frame because of the playerlist, so wouldn’t that mean all buttons would be invisible if this was the case?

Which buttons do you want to be visible and which invisible?(which condition must be true for any of these?)

1 Like

Just the image button for the local player. The screenshot below shows the friend request button. That imagebutton is under a frame, which is cloned to the same parent (that being the scrolling frame) for every player in the server. I want only the local player’s image button hidden for them.

What I’m trying to figure out is how would I make it so that only this imagebutton out of the rest is hidden to the local player since multiple of the same parent is cloned under scrolling frame

When making scripts like this, you must identify the condition that is true for that specific player. In our case the condition is Player.Name == frame.Name you can use that to disable the button for the specific frame.

local Players = game:GetService("Players")

local Player = Players.LocalPlayer

local ScrollingGui = script.Parent.ScrollingGui --your scrolling UI path
local frame = ScrollingGui:WaitForChild(Player.Name)
local button = frame:WaitForChild("ImageButton")

--button:Destroy() --destroy the button if you don't plan to use it anyway
--or else:
button.Visible = false
1 Like

Would you need double equal signs for that condition? Why would you, wouldn’t it work the same with just one?

= and == aren’t the same. = is used to set a value while == is used to check if a value is equal to another one.

In our case we can just retrieve the specific frame using ScrollingGui:WaitForChild(Player.Name) cause all the frames are named with player usernames.

1 Like

I just tried the script out and I think something is wrong. I checked scrolling frame to see if the GUI was cloned to there however nothing is there yet the gui still shows up. Is there something wrong?

Here’s the script that parents the frame

game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.PlayerList, false)

local players1 = game:GetService("Players")
local players2 = players1.LocalPlayer

local userId = players2.UserId
local thumbType = Enum.ThumbnailType.HeadShot
local thumbSize = Enum.ThumbnailSize.Size420x420
local content, isReady = players1:GetUserThumbnailAsync(userId, thumbType, thumbSize)

local function temp (player)
	local frame = game.ReplicatedStorage.Template:Clone()
	frame.Parent = script.Parent.Frame.ScrollingFrame
	frame.Name = player.Name
	frame.name.Text = player.Name
	frame.Visible = true
	frame.ImageLabel.Image = content
end

game.Players.PlayerAdded:Connect(function(plr)
	temp(plr)
end)

for _,players in pairs(game.Players:GetChildren()) do
	temp(players)
end

game.Players.PlayerRemoving:Connect(function(plr)
	for i,v in pairs(script.Parent.Frame.ScrollingFrame:GetChildren()) do
		if v.Name == plr.Name then
			v:remove()
		end
	end
end)