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

attempt to index a nil value problem?

Asked by 5 years ago

im having this problem :attempt to index a nil value i want to fix it there is the script:

function onTouch(part)

local human = part.Parent:findFirstChild("Humanoid")

if human ~= nil then

part.Parent:findFirstChild("Head").Transparency = 0.98

part.Parent:findFirstChild("Torso").Transparency = 1

part.Parent:findFirstChild("Left Arm").Transparency = 1

part.Parent:findFirstChild("Right Arm").Transparency = 1

part.Parent:findFirstChild("Left Leg").CanCollide = true

part.Parent:findFirstChild("Left Leg").Transparency = 1

part.Parent:findFirstChild("Right Leg").CanCollide = true

part.Parent:findFirstChild("Right Leg").Transparency = 1

end

end

script.Parent.Touched:connect(onTouch)

--COLORS

--1 = white

--208 = Light stone grey

--194 = Medium stone grey

--199 = Dark stone grey

--26 = Black

--21 = Bright red

--24 = Bright yellow

--226 = Cool yellow

--23 = Bright blue

--107 = Bright bluish green

--102 = Medium blue

--11 = Pastel blue

--45 = Light blue

--135 = Sand blue

--106 = Bright orange

--105 = Br. yellowish orange

--141 = Earth green

--28 = Dark green

--37 = Bright green

--119 = Br. yellowish green

--29 = Medium green

--151 = Sand green

--38 = Dark orange

--192 = Reddish brown

--104 = Bright violet

--9 = Light reddish violet

--101 = Medium red

--5 = Brick Yellow

--153 = Sand red

--217 = Brown

--18 = Nougat

--125 = Light orange

1 answer

Log in to vote
0
Answered by 5 years ago

Is your game using R15? If so, some of the body parts don't exist. Go to Game Settings in Roblox Studio (on the topbar). Go to Avatar, then look for Avatar Type, if it is marked as "R15", change it to R6. FindFirstChild returns nil when it fails to find the object.

Also, "findFirstChild" is deprecated. Use "FindFirstChild" instead.

If this answer helped you, make sure to mark it as solved.

0
THANK YOU BRO!!!! Te9chira 1 — 5y
Ad

Answer this question