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 4 years ago

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

Log in to vote
0
Answered by 4 years ago
Edited 4 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.

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)
Ad

Answer this question