local player
local distance
getplayer()
while wait(1) do
if player ~= nil then
print("Player is nil.")
else
getplayer()
wait()
distance = (script.Parent.Torso.Position - player.Torso.Position).magnitude
checkdistance()
end
end
function checkdistance()
if distance <= 15 then
print("Humanoid got Near")
end
end
function getplayer()
for _, inst in pairs(workspace:GetChildren()) do
if game.Players:GetPlayerFromCharacter(inst) then
player = inst
print(inst)
break
end
end
end
SOMEHOW IN THE OUTPUT IM GETTING A ATTEMPT TO CALL A NIL VALUE IN THE WHILE LOOP, WHEN I CLICK IT IT DIRECTS ME TO THE LINE WHERE IT SAYS else getplayer()
BUT ISN'T IT IMPOSSIBLE FOR THE FUNCTION BE CALLED BECAUSE IT WONT BE CALLED UNLESS THE PLAYER IS A NIL VALUE??

1 comment
I wanna upvote this answer but I can't!