so ive been working on this script that when a key is pressed it fires some functions to open a aura type thing around the player and it checks the magnitude around the player for other players. if a player is in certain distance from the local player it fires a function to damage them. but when i test or play the game and test it with a alt account eh game crashes. heres the script:
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local Char = Player.Character or Player.CharacterAdded:wait()
local db = true
local onn = false
local Distance = 15
game:GetService("UserInputService").InputBegan:Connect(function(input, event)
if input.KeyCode == Enum.KeyCode.Z and db then
db = false
if onn == false then
onn = true
elseif onn == true then
onn = false
end
for _,Plr in pairs(Players:GetPlayers()) do
if Plr ~= Player then
local Chr = Plr.Character
local HRP = Chr:WaitForChild("HumanoidRootPart")
repeat
if HRP and Player:DistanceFromCharacter(HRP.CFrame.Position) < Distance then
local MYHRP = script.Parent.HumanoidRootPart.CFrame.Position
local mag = (HRP - MYHRP).Magnitude
if mag < Distance then
script.Parent.FireKillingIntent:FireServer(HRP)
wait(0.5)
end
print("In Range")
end
until onn == false
end
end
wait(0.5)
db = true
end
end)
game:GetService("UserInputService").InputBegan:Connect(function(input, event)
if input.KeyCode == Enum.KeyCode.Z and db then
db = false
if onn == false then
onn = true
elseif onn == true then
onn = false
end
script.Parent.OpenkillingIntent:FireServer()
local san = game.Workspace.SAN.HumanoidRootPart
repeat
local HRP = Char.HumanoidRootPart.CFrame.Position
local mag = (san.CFrame.Position - HRP).Magnitude
if mag < Distance then
script.Parent.FireKillingIntent:FireServer(san)
wait(0.5)
end
until onn == false
wait(0.5)
db = true
end
end)
the first UserInputService function is for players and the second is for a npc in workspace i used for testing. i cant even get which line im crashing on because when the game crashes i have no choice but to leave. anyway i hope somone can help me, and thank you!

2 comments
Thank you! i diddnt realise that but thanks!
np!