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

Why does player become nil, when I try to find it?

Asked by 5 years ago

At output it's prints nil, instead of my name ingame. Here is the code:

local playerToFind = hit.Parent.Name -- Hit is the way I find out what touched the brick.
local playerService = game:GetService("Players")
local player  = playerService:FindFirstChild(playerToFind)
print(player)

I really have no idea why, I hope someone can help me. - Toby

0
It works sometime. tobiO0310 58 — 5y
0
Nvm works now.... tobiO0310 58 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

The problem is that at line 4, you didn't convert the name of the player. You can just do:

print(player.Name)
Ad

Answer this question