Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How can I make my TextButton work only on specific players?

So I'm making a text button that triggers only when a specific player presses it.

This is the code:

local button = script.Parent

local groupServie = game:GetService("GroupService")

button.MouseButton1Click:Connect(function (plr)
	if plr.Name == "ElpersonPL" then
		print("good plr")
	end
	
end)

The game says that I'm trying to index nil with "Name"

1 answer

I think you have to get the LocalPlayer instead of getting it from the parameter since I think it gets the player's mouse, not the player. Also, make sure it's a LocalScript.

local button = script.Parent

local groupServie = game:GetService("GroupService")

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

button.MouseButton1Click:Connect(function()
	if localPlayer.Name == "ElpersonPL" then
		print("good plr")
	end
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.