Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 6 years ago
Edited 6 years ago

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

Log in to vote
0
Answered by 6 years ago

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

Ad

Answer this question