Gate = script.Parent local player = game:GetService("Players").LocalPlayer Gate.Touched:Connect(function(hit) wait() if hit and hit.Parent:FindFirstChild("Humanoid") then local head = player.Head local ltorso = player.LowerTorso local utorso = player.UpperTorso local lleftarm = player.LeftLowerArm local uleftarm = player.LeftUpperArm local lrightarm = player.RightLowerArm local urightarm = player.RightUpperArm local lleftleg = player.LeftLowerLeg local uleftleg = player.LeftUpperLeg local lrightleg = player.RightLowerLeg local urightleg = player.RightUpperLeg local lhand = player.LeftHand local rhand = player.RightHand local lfoot = player.LeftFoot local rfoot = player.RightFoot wait(1) lhand.Colour = {255, 255, 255} -- Imagine I've set everything to "255, 255, 255", I was just using "lhand" to test end end)
This is a script I've got that should change the Player's skin colour once touched a part, it doesn't work and in the output I get ' attempt to index nil with "Head" ', can anyone help please?
Theres a couple things wrong with this, first its in a server script and when it gets touched by anything with a humanoid itll change everyones color, 2nd you cant get local player in a server script, and third the character limbs are located in localplayer.Character not in the LocalPlayer and fourth your not setting the color right.
Gate = script.Parent local players = game:GetService("Players") Gate.Touched:Connect(function(hit) if hit and hit.Parent:FindFirstChild("Humanoid") then local Char = hit.parent --this contains all the character limbs local Name = Char.Name local plr = players[Name] --the plr isnt required here but this is how you would get it anyway --creating variables for components inside of a group manually isnt very efficient wait(1) for i,v in pairs(Char:GetChildren()) do --creating table with the Characters cilds(components inside the Character) if v:IsA("MeshPart") then --if the child is a meshpart which the limbs are then.. v.Color = Color3.new(255,255,255) --change the meshparts color to whatever you set end end end end)
also i made it shorter, hopefully this helps
Gate = script.Parent local player = game:GetService("Players").LocalPlayer Gate.Touched:Connect(function(hit) wait() if hit and hit.Parent:FindFirstChild("Humanoid") then local player = hit.Parent -- player was not equal to anything local head = player.Head local ltorso = player.LowerTorso local utorso = player.UpperTorso local lleftarm = player.LeftLowerArm local uleftarm = player.LeftUpperArm local lrightarm = player.RightLowerArm local urightarm = player.RightUpperArm local lleftleg = player.LeftLowerLeg local uleftleg = player.LeftUpperLeg local lrightleg = player.RightLowerLeg local urightleg = player.RightUpperLeg local lhand = player.LeftHand local rhand = player.RightHand local lfoot = player.LeftFoot local rfoot = player.RightFoot wait(1) lhand.Color = Color3.fromRGB(255, 255, 255) -- Spelled Color Wrong and did not format Color Correctly end end)