local Players = game:GetService("Players")
local Player = Players.LocalPlayer
print(Player.Name)
Yeah I noticed that, I’ll actually make that the solution since I solved it already to a issue relating to that.
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?)
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
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.
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)
As I said ScrollingFrame
is your scrolling frame path. You have to replace the variable path
to its location depending on your script. Also cause your main script is running on the client, you can just do:
if player.Name == player2.Name then
frame.ImageButton.Visible = false
--or
--frame.ImageButton:Destroy()
end
Inside your temp
function.
That seemed to hide it, but before I give you the solution, would you mind joining my game to see if it hides for the local player and not every other button (I know it will be different for you)?
You can test that yourself, using the local server feature inside Roblox Studio. Go to the Test tab > Local Server 2 players > Start
.
But wouldn’t that be the server size, not actually 2 players in the test?
It creates 3 Roblox studio windows, one representing the server, and the other 2 each player(They will be named Player1, Player2).
Nevermind, it worked. I’ll give you the solution! Thanks for the help man!
I forgot to give you the solution, sorry about that.