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
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