script.Parent.Touched:connect(function(hit)
local humanoid = hit.Parent:FindFirstChild("Humanoid")
local p = game.Players:GetPlayerFromCharacter(humanoid.Parent) p.PlayerGui.Inv.OpenInventory.Inventory.Boarder.SlotOne.Image = ""
end)
This is suppose to make the Image dissapear, But doesn't work giving me this error.
Workspace.Speed.Script:5: attempt to index local 'humanoid' (a nil value)
FindFirstChild
either returns the child you're looking for, or it returns nil. If anything other than a Character touches this brick, then it will return nil, because hit.Parent
would obviously not have a humanoid. This is your error. FindFirstChild
is returning nil, then you are trying to essentially write
nil.Parent
which results in the error.
All you need to do is check if it's nil or not, using an if statement:
local humanoid = hit.Parent:FindFirstChild("Humanoid") if humanoid ~= nil then --etc. end
Or, equivalently:
local humanoid = hit.Parent:FindFirstChild("Humanoid") if humanoid then --etc. end