Hitbox Issue with Magnitude

For some reason, my hitbox hits players where ever you are…

Local Script:

local UIS = game:GetService("UserInputService")
local RP = game:GetService("ReplicatedStorage")
local Event = RP:WaitForChild("RemoteEvent")
local Cooldown = false

UIS.InputBegan:Connect(function(input, typing)
	if typing then return end
	if input.KeyCode == Enum.KeyCode.R then
		if Cooldown == true then return end
		if Cooldown == false then
			Event:FireServer()
			Cooldown = true
			wait(3)
			Cooldown = false
		end
	end
end)

Server Script

local RP = game:GetService("ReplicatedStorage")
local Event = RP:WaitForChild("RemoteEvent")
local SS = game:GetService("ServerStorage")
local Base = SS:WaitForChild("Base")
local Ring = SS:WaitForChild("EnergyRing")
local TS = game:GetService("TweenService")

Event.OnServerEvent:Connect(function(player)
	local char = player.Character
	local humRP = char:FindFirstChild("HumanoidRootPart")
	
	for i, v in pairs(game.Workspace:GetChildren()) do
		if v:IsA("Model") then
			if v ~= char then
				if (humRP.Position - v.HumanoidRootPart.Position).Magnitude - 6.75 then
					Base.Parent = workspace
					Base.Position = humRP.Position
					Ring.Parent = workspace
					Ring.Position = Base.Position
					local Tween = TweenInfo.new(0.75, Enum.EasingStyle.Back, Enum.EasingDirection.Out, 0, false, 0)
					local Goals = {}
					Goals.Size = Vector3.new(20,20,20)
					local Start = TS:Create(Base, Tween, Goals)
					Start:Play()
					local Tween1 = TweenInfo.new(0.75, Enum.EasingStyle.Back, Enum.EasingDirection.Out, 0, false, 0)
					local Goals1 = {}
					Goals1.Size = Vector3.new(21,21,21)
					local Start1 = TS:Create(Ring, Tween1, Goals1)
					Start1:Play()
					v.Humanoid:TakeDamage(5)
					wait(0.80)
					local Tween2 = TweenInfo.new(0.75, Enum.EasingStyle.Back, Enum.EasingDirection.In, 0, false, 0)
					local Goals2 = {}
					Goals2.Size = Vector3.new(0.5, 0.5, 0.5)
					local Start2 = TS:Create(Base, Tween2, Goals2)
					Start2:Play()
					local Tween3 = TweenInfo.new(0.75, Enum.EasingStyle.Back, Enum.EasingDirection.In, 0, false, 0)
					local Goals3 = {}
					Goals3.Size = Vector3.new(1,1,1)
					local Start3 = TS:Create(Ring, Tween3, Goals3)
					Start3:Play()
					wait(0.80)
					Base.Parent = game.ServerStorage
					Ring.Parent = game.ServerStorage
				end
			end
		end
	end
	
end)

Please help!

You’re not really comparing anything, you might want to change

if (humRP.Position - v.HumanoidRootPart.Position).Magnitude - 6.75 then

to

if (humRP.Position - v.HumanoidRootPart.Position).Magnitude < 6.75 then

if you want to check if there is a distance smaller than 6.75 between the players

1 Like

Alright, I checked it out and it worked! Thanks.

1 Like