Function not running in localscript even if its called

I am making a render distance scirpt (I CAN’T SPELL!), but, when my player moves, nothing happens. What in the world is happening here?
I added as many print statements as possible, the ones outside the function seems to be working, but the ones inside are not working.

local player = game.Players.LocalPlayer
print("script loaded")
print("waiting for character")
player.CharacterAdded:Wait()
print("character added")
local character = player.Character
local humanoidRootPart = character:WaitForChild("HumanoidRootPart")
local MAX_MAGNITUDE = 2 --the render distance




local function loop()
	print("function works!")
	--loop through the workspace
	print("[debug] looping")
	for _, v in ipairs(workspace:GetDescendants()) do
		--check if the current object in the loop is a valid part
		if v:IsA("BasePart") then
			--check if the part is distant enough to be rendered
			if (v.Position - humanoidRootPart.Position).Magnitude <= MAX_MAGNITUDE then
				--render if it is not distant from more than 120
				v.Transparency = 0
				--if it's more distant than the render distance, then don't render it
			else
				print("hiding part")
				v.Transparency = 1
			end
		end
	end
end

print("now tracking movement")
--detect player movement
humanoidRootPart:GetPropertyChangedSignal("Position"):Connect(loop)

if ur wondering its also on starterplayerscripts

I think Position is one of the properties that don’t fire a changed signal.

Use CFrame. If that doesn’t work try something else like RenderStepped.

the cframe one doesn’t work too, but the renderstepped one worked but it’s very laggy, i want a solution that doesn’t lag studio

I recommend you look at Instance Streaming instead of implementing your own version.