Magnitude not working properly

I think it may be the logic or something but I don’t know much. I’ve tried debugging it but I couldn’t find anything that would’ve caused the issue.
Code:

local Part = workspace.TestPart
warn(Part.CurrentTargetCharacter.Value)

while wait(1) do
	for index, value in ipairs(game:GetService("Players"):GetPlayers()) do
		local CharacterAdded = value.Character or value.CharacterAdded:Wait()
		local HRP = value.Character.HumanoidRootPart
		local RakeModel = Part

		local Distance = (HRP.Position - RakeModel.Position).Magnitude
		if Distance <= 100 then
			warn("hey!")
			if Distance < Part.CurrentTargetMagnitude.Value then
				Part.CurrentTargetMagnitude.Value = Distance
				Part.CurrentTargetCharacter.Value = value.Character
			end
		end
		print(value, Distance)
		if Distance > 100 and Part.CurrentTargetCharacter.Value ~= nil then
			print("Too far!")
			Part.CurrentTargetCharacter.Value = nil
		else
			warn("Close!")
		end
	end
end

What type of Value is this? Boolean? String? it appears to be a number Value I assume?

1 Like

ObjectValue. (CharacterLimitMoment)

So if its not being set to nil what is it being set to?

The closest Player’s Character


So here it should only pick the players character up at 100 studs or less?

And here if the player is above 100 studs away it does not pick them up anymore correct-o?

Yes. It pick’s the closest player if there in 100 Studs.

Yes. If the closest player is further then 100 studs, it doesn’t target anyone and CurrentTargetCharacter.Value should be nil.

image
Well if its not set to nil then it wont ever be set to nil ??

It starts as nil. That code means if it’s not equal to nil then [code].

Yes it starts as nil but if its not set to nil after how will It be set back to nil cause your argument says that

if Distance > 100 and Part.CurrentTargetCharacter.Value ~= nil then
end

— This dosent run if Part.CurrentTargetCharacter.Value == true and once its set to true it can be set to nil again because of that argument.

Let me try that. I don’t think it would work because it’s a ObjectValue, not a bool.

Well True could also mean not nil !!

like

ObjectValue = workspace.Character - This is not False or Nil cause its true.

Doesn’t seem to work. It makes the script break and both CurrentMagnitude and CurrentCharacter stop completley.

Can u send me a copy of your workspace then ! So I can check it out

Managed to figure it out. I just had to check .Value existed and if it did reset the values.
Here it is incase I’m hallucinating or something:

local Part = workspace.TestPart
warn(Part.CurrentTargetCharacter.Value)

while wait(1) do
	for index, value in ipairs(game:GetService("Players"):GetPlayers()) do
		local CharacterAdded = value.Character or value.CharacterAdded:Wait()
		local HRP = value.Character.HumanoidRootPart
		local RakeModel = Part

		local Distance = (HRP.Position - RakeModel.Position).Magnitude
		if Distance <= 100 then
			warn("hey!")
			if Distance < Part.CurrentTargetMagnitude.Value then
				Part.CurrentTargetMagnitude.Value = Distance
				Part.CurrentTargetCharacter.Value = value.Character
			end
		end
		print(value, Distance)
		if Distance > 100 and Part.CurrentTargetCharacter.Value then
			print("Too far!")
			Part.CurrentTargetCharacter.Value = nil
			Part.CurrentTargetMagnitude.Value = 100
		else
			warn("Close!")
		end
	end
end

Yea I was thinking that had something to do with it Great Job :+1:

Thanks. It works fully now. Now the hardest part is making it move to them and attack. :+1: