Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why does this script always print "nil" instead of the body parts?

im trying to make a thing like when u click a part it scans the players which r touching the part, i wanted to test out GetTouchingParts() so i made it so whatever items are touching the part, it prints their name. when i go inside the part and click scan, it just prints nil 4 times here is the script

local clickdetector = script.Parent.ClickDetector
local scanpart = game.Workspace.SCANPART
local touchingparts

script.Parent.ClickDetector.MouseClick:Connect(function()
	wait(1.5)
	touchingparts = scanpart:GetTouchingParts()
	print(touchingparts[1])
	print(touchingparts[2])
	print(touchingparts[3])
	print(touchingparts[4])
end)

1 answer

Its because you defined local at top as nil so it will print nil just delete the local touchingparts part

2 comments

0

how can i fix it?? do i just create a new variable

0

The variable 'touchingparts' has no value, so saying 'print(touchingparts[#])' will print Nil

This discussion is preserved as it was. New answers, comments, and votes are closed.