So, i’m trying to make a button print the player’s name when pressed, the thing is, the button is stocked inside a SurfaceGui…
How do i make it print the player?
I’ve tried some thing like this:
I've tried something like this:
local Players = game.Players:GetChildren()
local UserInputService = game:GetService("UserInputService")
script.Parent.MouseButton1Down:Connect(function(number)
print(game.Players:GetCharacterAppearanceInfoAsync(number))
end)
…and it printed me ▶ {...}
Which lead to the following:
▼ { ["assets"] = {}, ["bodyColors"] = ▶ {...}, ["defaultPantsApplied"] = false, ["defaultShirtApplied"] = false, ["emotes"] = {}, ["playerAvatarType"] = "R6", ["scales"] = ▼ { ["bodyType"] = 0, ["depth"] = 1, ["head"] = 1, ["height"] = 1, ["proportion"] = 0, ["width"] = 1 } }
Yeah, basically, it just listed all the properties of the player…
How do i make it print the player, knowing its a normal script, not a local one and that the script is inside a button inside a SurfaceGui ?
You have to put your SurfaceGui inside the StarterGui and use his “Adornee” properties to render it on the selected object.
The Ui’s buttons can’t work if your Gui are placed inside the workspace.
local plr = script.Parent.Parent:GetPlayerFromCharacter(Players)
print(plr.Name)
i think the surface gui is found as a child of the player character so the script is a child of the surface gui so when you refer to the player character you get it with GetPlayerFromCharacter()and it’s easier that way
Alright, So let’s put them inside the StarterGui, and check out inside the SurfaceGui properties, there is something called Adornee, click it and select the right part/mesh in the workspace where you want it to be, it should get rendered.
I found the solution, i used :GetPlayers and a for loop to do the job
local Players = game.Players:GetChildren()
local UserInputService = game:GetService("UserInputService")
script.Parent.MouseButton1Down:Connect(function(number)
for i,v in pairs(game.Players:GetPlayers(number)) do
v.PlayerGui.Spectate.Enabled = true
end
end)