I’m basically making a hover feature with selection box that detects for a humanoid, when it does that the players body turns into a new color and different material, but I’m getting an error saying “attempting to index nil with Parent” on line 37
I don’t really know what I am doing wrong but the hover feature works just not the hover off which is what I’m trying to fix
--Hover off player with mouse
if Selection.Adornee ~= nil then
Selected = nil
Selection.Parent = nil
Selection.Adornee = nil
local target = mouse.Target
local humanoid = target.Parent:FindFirstChild('Humanoid') or target.Parent.Parent:FindFirstChild('Humanoid')
for i, v in pairs(humanoid.Parent:GetChildren()) do
if v:IsA("Part")and v.Color == Color3.fromRGB(186, 75, 255) then
v.Material = Enum.Material.Plastic
v.Color = humanoid.Parent["Body Colors"].Head
The target is the part that the mouse hover and the parent is the character so if write say target.Parent you get che character model but if you write .Parent.Parent you are going out of the model so there’s not any humanoid.
RunService.RenderStepped:Connect(function()
local target = mouse.Target
if target then
local humanoid = target.Parent:FindFirstChild('Humanoid') or target.Parent.Parent:FindFirstChild('Humanoid')
if humanoid then
if Selection.Adornee ~= humanoid.Parent then
Selected = humanoid.Parent
Selection.Parent = humanoid.Parent
Selection.Adornee = humanoid.Parent
for i, v in pairs(humanoid.Parent:GetChildren()) do
if v:IsA("Part") then
v.Material = Enum.Material.ForceField
v.Color = Color3.fromRGB(186, 75, 255)
end
end
end
else
It already works when I hover on though, I don’t understand why not here
But why do you need this? If you already get the Humanoid here:
Is this working?
With target you are getting the part that the mouse is hovering, adding a Parent you are getting the character model, adding another Parent you are getting something out of the character model.
Use just:
local humanoid = target.Parent:FindFirstChild("Humanoid")
None of these are working. Still the same error
RunService.RenderStepped:Connect(function()
local target = mouse.Target
if target then
local humanoid = target.Parent:FindFirstChild('Humanoid')
if humanoid then
if Selection.Adornee ~= humanoid.Parent then
Selected = humanoid.Parent
Selection.Parent = humanoid.Parent
Selection.Adornee = humanoid.Parent
for i, v in pairs(humanoid.Parent:GetChildren()) do
if v:IsA("Part") then
v.Material = Enum.Material.ForceField
v.Color = Color3.fromRGB(186, 75, 255)
end
end
end
else
Why do you keep using: target.Parent.Parent:FindFirstChild("Humanoid")
this doesen’t work.
Wait now I’ve noted this, you are using the variable humanoid to use it in the for function but you don’t need it because you can simple do this:
for i, v in pairs(target.Parent:GetChildren()) do
Could you try this:
RunService.RenderStepped:Connect(function()
local target = mouse.Target
local character = target.Parent
if target then
local humanoid = character:FindFirstChild("Humanoid")
if humanoid then
for i, v in pairs(character:GetChildren()) do
if v:IsA("MeshPart") then
v.Material = Enum.Material.ForceField
v.Color = Color3.fromRGB(186, 75, 255)
end
end
end
end
end)
1 Like
@you_between Try to use this without the Selection part, I haven’t added it because I don’t know what it is because you haven’t send the full script and I think that it can be the problem