Problem while trying to detect the player with "MouseButton1Down"

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 ?

Thanks in advance.

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.

you should do this:

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

Not really, it’s in a whole different part

They are placed inside a part (character limit)

Does that part have nothing to do with the character? in that case you should do what he said @Crygen54

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.

2 Likes

Not at all, it’s a SurfaceGui placed inside a computer mesh i modeled, the buttons do work, but it just prints me a list of the properties of the char

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)

That was actually a good idea, but i really wanted to keep it inside the model incase i somehow forget where it is

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.