So I have this cut section of my code, which errors because 'location' is continously nil. How would I update the location to actually make the bit of code function as intended?
function randomLocation() local parts = game.Workspace.Tier1:GetChildren() if #parts > 0 then random = parts[math.random(1, #parts)] end return random end function getPosition() local parts = game.Workspace.Tier1:GetChildren() if #parts > 0 then loc = randomLocation() end return loc end local location = getPosition() Tool = script.Parent.Parent hum.Changed:Connect(function() --while true do wait(0.1) if hum.Health > 0 then --local parts = game.Workspace.Tier1:GetChildren() --if #parts > 0 then if location ~= nil then getPosition() print'got pos' local location = getPosition().Position if game.Workspace.Tier1:FindFirstChild("Chest") then local head = Character:FindFirstChild("Head") or Character:WaitForChild("Head") local distance = (head.Position - location).magnitude