Getting Player In a Server Script

I was trying to get a Value inside of Player but when I try to print Player it returns Nil.

local Players = game:GetService("Players")

script.Parent.Touched:Connect(function(hit)
	local player = Players:GetPlayerFromCharacter(hit.Parent)
	print(player)

Like I said, the print returns nil into the output.

You need to make sure that hit.Parent is actually a character model.


local Players = game:GetService("Players")

script.Parent.Touched:Connect(function(hit)
    local player = Players:GetPlayerFromCharacter(hit.Parent)
    if player ~= nil then
        print(player)
    end
end)
1 Like

if player then would suffice.