When I want to print the LocalPlayers name, all I get is "nil"

I have a piece of code that I want to print out when they press the “Golden Button” so I know who presses it. I read another post and I was able to fix my mistake, and it is printing in the console, but it is only printing “nil” instead of the player’s name. Any Ideas as to where I can fix it?

Image:
image

print(tostring(localplayer), ‘has pressed the emergency meeting’)


Can you send us the whole code? It’d also be helpful if it weren’t an image.

if localplayer is game.Players.LocalPlayer: do

print (localplayer.Name, "has pressed the button")
1 Like

Here is the whole script i’m using

– locals –

local groupId = 5879349
local minrank = 253
local golden = game.Workspace.judgetable.Table.goldenbutton
local chloe = game.Workspace.judgetable.Table.chloebutton
local ben = game.Workspace.judgetable.Table.benbutton
local donut = game.Workspace.judgetable.Table.donutbutton
local beems = game.Workspace.judgetable.Table.beemsbutton
local beemsstar = game.Workspace.judgetable.Stars.beanstar
local donutstar = game.Workspace.judgetable.Stars.donutstar
local benstar = game.Workspace.judgetable.Stars.benstar
local chloestar = game.Workspace.judgetable.Stars.chloestar
local starmodel = game.Workspace.judgetable.Stars
local localplayer = game.Players.LocalPlayer

– x buttons –

chloe.ClickDetector.MouseClick:Connect(function(player)
if player:GetRankInGroup(groupId) >= minrank then
print(“chloe button pressed”)
chloestar.BrickColor = BrickColor.new(“Really red”)
end
end)

ben.ClickDetector.MouseClick:Connect(function(player)
if player:GetRankInGroup(groupId) >= minrank then
print(“ben button pressed”)
benstar.BrickColor = BrickColor.new(“Really red”)
end
end)

donut.ClickDetector.MouseClick:Connect(function(player)
if player:GetRankInGroup(groupId) >= minrank then
print(“donut button pressed”)
donutstar.BrickColor = BrickColor.new(“Really red”)
end
end)

beems.ClickDetector.MouseClick:Connect(function(player)
if player:GetRankInGroup(groupId) >= minrank then
print(“donut button pressed”)
beemsstar.BrickColor = BrickColor.new(“Really red”)
end
end)

– golden buzzer –

golden.ClickDetector.MouseClick:Connect(function(player)
if player:GetRankInGroup(groupId) >= minrank then
print(localplayer, “has pressed the button”)
for num, child in pairs(starmodel:GetChildren()) do
if child:IsA(‘UnionOperation’) then
child.BrickColor = BrickColor.new(“Bright yellow”)
end
end
end
end)

I only really care about the golden buzzer script, but I could implement it into the other persons buttons aswell. For context as well, this game is a Got Talent type game.

Refer to my post above. That should be the solution

1 Like

All I get from the console is " ServerScriptService.button/star:53: attempt to index nil with ‘Name’"

That means that you’re probably executing this code on the Server. You’re going to need to add a parameter (plr or player, preferably) to the MouseClick event, and do plr.Name.

3 Likes

Is this a localscript or just a script?

1 Like

I still get “nil” in the console. Should I try a actual game test? I am doing studio tests at the moment.

this is funny, localplayer returns nil in the server

1 Like

Is that in a server script or a local script? Local player always returns nil if it’s called from the server

1 Like

It is a normal script in ServerScriptService.

Omg, it finally works. Thank you so much.

If this is in a LocalScript (as you are using LocalPlayer), then change the LocalPlayer in this section with the player parameter in the function:

golden.ClickDetector.MouseClick:Connect(function(player)
if player:GetRankInGroup(groupId) >= minrank then
    print(player, “has pressed the button”)
        for num, child in pairs(starmodel:GetChildren()) do
            if child:IsA(‘UnionOperation’) then
                child.BrickColor = BrickColor.new(“Bright yellow”)
            end
        end
    end
end)

Try this and see if it works. If not, then I recommend putting this section in a regular script and use a RemoteEvent to communicate with the client if you really need this to be client-sided.

(Well, it looks like you fixed it, but I’ll still post it since I think it is still useful).