Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

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

Asked by 5 years ago

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

This is the code:

01local button = script.Parent
02 
03local groupServie = game:GetService("GroupService")
04 
05button.MouseButton1Click:Connect(function (plr)
06    if plr.Name == "ElpersonPL" then
07        print("good plr")
08    end
09 
10end)

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

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

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.

01local button = script.Parent
02 
03local groupServie = game:GetService("GroupService")
04 
05local localPlayer = game:GetService("Players").LocalPlayer
06 
07button.MouseButton1Click:Connect(function()
08    if localPlayer.Name == "ElpersonPL" then
09        print("good plr")
10    end
11end)
Ad

Answer this question