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

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

Asked by 3 years ago

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

01local clickdetector = script.Parent.ClickDetector
02local scanpart = game.Workspace.SCANPART
03local touchingparts
04 
05script.Parent.ClickDetector.MouseClick:Connect(function()
06    wait(1.5)
07    touchingparts = scanpart:GetTouchingParts()
08    print(touchingparts[1])
09    print(touchingparts[2])
10    print(touchingparts[3])
11    print(touchingparts[4])
12end)

1 answer

Log in to vote
0
Answered by 3 years ago

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

0
how can i fix it?? do i just create a new variable InspireWithFun 9 — 3y
0
The variable 'touchingparts' has no value, so saying 'print(touchingparts[#])' will print Nil dxrrevn 13 — 3y
Ad

Answer this question