The script (localscript) works as intended, but whenever I playtest, it outputs "Attempt to index nil with FindFirstChild
, (only when looking at the sky.) This makes it next to impossible to read anything in the output, since it's being occupied by a gazillion of these errors.
Here's the script, hope someone can help:
`local player = game.Players.LocalPlayer local mouse = player:GetMouse()
mouse.Move:Connect (function() local target = mouse.Target
if target:FindFirstChild ("dex") then target.dex.Enabled = true if target.Transparency == 1 then target.dex.Enabled = false end elseif target:FindFirstChild ("Berry") then target.Berry.dex.Enabled = false end
end)`
I'm a rookie at coding, so don't judge if the code's terrible ????
the problem is that you not checking if target exists, when u look at the sky, There's nothing (unless theres a part in the sky) so target is nil, to fix it, add another if statement to check if target exists and if it has a parent
local player = game.Players.LocalPlayer local mouse = player:GetMouse() mouse.Move:Connect (function() if mouse.Target then -- check if there's a target else it'll error local target = mouse.Target end end if target and target.Parent then if target:FindFirstChild ("dex") then target.dex.Enabled = true if target.Transparency == 1 then target.dex.Enabled = false end elseif target:FindFirstChild ("Berry") then target.Berry.dex.Enabled = false end end end