Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Magnitude script runs the action when its not supposed to? Also runs multiple times?

I have been working on a magnitude script and I got it working.

But heres the problem its supposed to print when the other player is within 10 studs of the local player.

But instead it prints all the time and it prints 2 times when the player is in 10 studs of the local player.

I want it to not print at all and only print when the player is 10 studs of another player.

Heres the script.

for _, TargetPlayer in pairs(game.Players:GetPlayers()) do
	if  TargetPlayer then 
		local TargetCharacter = TargetPlayer.Character
		local Magnitude = (MainPlayer.Position - 			
                TargetCharacter.HumanoidRootPart.Position).magnitude
		if Magnitude <= 10 then
			print("They are too close!")
		end
	end
end

Thank you for your time and happy new year! :)

1 answer

✓ Accepted answer

Flip the Greater than symbol around I think, either that or I'm just retarded

This discussion is preserved as it was. New answers, comments, and votes are closed.