Magnitude not working on big parts

Hello everyone, I’m developing a zombie game.
I decided to make a custom swimming script using magnitude, but when I tested, it didn’t work. I think it might not work on big sized parts.

demonstration:

script server:

game:GetService(“RunService”).Heartbeat:Connect(function()
if game.Workspace:FindFirstChild(“Map”) then
for i,v in pairs(game.Workspace.Map.Waters:GetChildren()) do
if v.ClassName == “Part” or v.ClassName == “MeshPart” then
if (v.Position-script.parent.HumanoidRootPart.Position).Magnitude <= 5 then
script.parent.IsSwimming.Value = true
else
script.parent.IsSwimming.Value = false
end
end
end
else
script.parent.IsSwimming.Value = false
end
end)

idk how to fix it… please help me

2 Likes

Are you getting any errors in the output? Also, I think you uploaded the video file as an audio so I’m not able to view it.

1 Like

Magnitude should work 99% of the time. Have you tried printing the magnitude value?

The parts size probably has an influence, if the parts size is 10 and your magnitude check is greater than 10 then you wouldnt be in range because you cant go through the part to get in range. It’s like a ball in a square. You want a square in a ball

This means you should add the size to the magnitude check, if you wanted to get a distance of 10 you would add the size of the part, if the parts size is 5,5,5 10+5 = 15

1 Like

yes i have tried printing it… i will show for you

no i am not getting error outputs

oh that’s was the problem… it was size of part … it solved my problem… thanks dude

No problem bro! :), glad to help