Script not refrencing number value

So basically I have a script that creates a magnitude range/distance between player and npc.But for some reason it seems to not be able to reference the number value, even though their are no errors in output, and the values location is not changing. If I where to put a normal number for “MaxDistance” it would work like normal. Any idea why?


local npc = script.Parent
local hrpOfNPC = npc:WaitForChild("HumanoidRootPart")

local plrsHit = {}

local maxDistance = script.Parent.Mimicry.Range.Value

while true do
	local plrs = game.Players:GetPlayers()
	local closestHRP
	for i, plr in pairs(plrs) do
		if plr.Character and plr.Character:FindFirstChild("HumanoidRootPart") and plr.Character.Humanoid.Health > 0 then
			local hrp = plr.Character.HumanoidRootPart
			local distanceBetween = (hrpOfNPC.Position - hrp.Position).Magnitude
			if not closestHRP then closestHRP = hrp end

			if (hrpOfNPC.Position - closestHRP.Position).Magnitude > distanceBetween then
				closestHRP = hrp
	if closestHRP and (hrpOfNPC.Position - closestHRP.Position).Magnitude <= maxDistance then 
		npc.Humanoid:MoveTo(closestHRP.Position -,0,-1.2))
		script.Parent.Mimicry.IsIdle.Value = false script.Parent.Mimicry.Range.Value = 80
	 if closestHRP and (hrpOfNPC.Position - closestHRP.Position).Magnitude > 80 then 
		script.Parent.Mimicry.IsIdle.Value = true

1 Like

A common mistake is to forget to reference an item like
maxDistance = script.Parent.Mimicry.Range.Value (you could use npc.Mimicry,Range.Value instead)
instead of
maxDistance = npc.Mimicry.Range.Value.Value

I can’t tell if you’ve renamed the Value to Range, or if Value is a child of Range.

1 Like