Hello,
I am trying to stop it from erroring when it cannot find the object "Config" but I haven't been able to figure it out.
local user = tool.Parent local ray = Ray.new(tool.MuzzleFlash.CFrame.p, (target - tool.MuzzleFlash.CFrame.p).unit*300) local hit, position = game.Workspace:FindPartOnRay(ray, user) local TargetObj = hit and hit.Parent.Parent:FindFirstChild("Config") local DamageObj = TargetObj if DamageObj then DamageObj.Hull.Value = DamageObj.Hull.Value - 25 end
Any help would be appreciated
Line 5 is a little bit confusing hit and hit.Parent.Parent:FindFirstChild("Config")
will return true or false and set that to the variable TargetObj
then on the next line you're simply creating a new variable for the same value, perhaps you just want to remove hit and
?
local user = tool.Parent local ray = Ray.new(tool.MuzzleFlash.CFrame.p, (target - tool.MuzzleFlash.CFrame.p).unit*300) local hit, position = game.Workspace:FindPartOnRay(ray, user) local TargetObj = hit.Parent.Parent:FindFirstChild("Config") if TargetObj then TargetObj .Hull.Value = TargetObj .Hull.Value - 25 end