I just got into learning magnitude yesterday night in an effort to try to get something working.
My goal at the moment is to, well I am working on Darth Vader and I want him to choke people who are around him when he presses Q.
I am using magnitude so the script knows who is near him when he uses the move.
But I am a little lost, magnitude is something ive never worked with and all the tutorials on it are 4 years old or older.
So heres what ive got so far in my script but its not working nor does it error. Anyone know why.
I am trying to make it so if you are near Vader when he presses Q it basically kills the people around him except Vader himself.
Heres the script so far.
local function onKeyPressed(inputObject, gameProcessedEvent)
if inputObject.KeyCode == Enum.KeyCode.Q then
local MainPlayer = Player.Character:WaitForChild("HumanoidRootPart")
local OtherPlayer = game.Players:GetChildren()
for _, TargetPlayer in pairs(game.Players:GetChildren()) do
if not TargetPlayer == MainPlayer then
local Magnitude = (MainPlayer.Position - TargetPlayer.Position).magnitude
if Magnitude <= 10 then
print("They are too close!")
end
end
end
elseif inputObject.KeyCode == Enum.KeyCode.E then
elseif inputObject.KeyCode == Enum.KeyCode.R then
end
end
UserInputService.InputBegan:connect(onKeyPressed)
Im sorry the indentations are weird, its inside a onEquipped function inside a tool.
Thank you for your time. Also happy new year!

2 comments
Who's ""MainPlayer?? Don't hurt him! D:
Main player is defined at the top of the script. Its game.Players.LocalPlayer