Magnitude Problem

Hi im need help to how make magnitude only get one character
script:
function Ability ()
if Tool.Parent.Name == “Backpack” then return end
if debounce then return end
if ispassive then return end
if plr.Character.IsRag.Value then return end
if plr.Character:FindFirstChild(“CantAbility”) then return end
local human = plr.Character:FindFirstChildWhichIsA(“Humanoid”)
for i,v in pairs(workspace:GetChildren()) do
if v:IsA(“Model”) and v.Name ~= plr.Character.Name then

		if v:FindFirstChildWhichIsA("Humanoid") then
			if v:FindFirstChild("Invicible") or v.IsRag.Value then return
			end
			local humanoid = v:FindFirstChildWhichIsA("Humanoid")
			local torso = v:FindFirstChild("Torso")
			local pos = (plr.Character.Torso.Position - torso.Position)
			if pos.Magnitude <= 70 then
				debounce = true
				spawn(function()
					wait(22.6) --cooldown for fart wall
					debounce = false
				end)
				if game.Workspace:FindFirstChild(plr.UserId.."BUS+BUS") then
				game.Workspace:FindFirstChild(plr.UserId.."BUS+BUS"):Destroy()
				end
			
				local bus = game.ServerStorage.BusModel:Clone()
			bus.Parent = workspace
			bus.Script.Enabled = true
			bus.Name = plr.UserId.."BUS+BUS"
			local apart = Instance.new("Part",workspace)
			apart.CFrame = torso.CFrame * CFrame.new(0,5,200)
			monar(apart,0.1)
			
				Tool.Cd:Clone().Parent = plr.PlayerGui
				bus:PivotTo(v:GetPivot() * CFrame.new(0,5,500))
	monar(bus,2)
		
			for i,v in pairs(bus:GetChildren())  do
				if v:IsA("MeshPart") or v:IsA("BasePart")  then
					v.CanCollide = false
					v.CastShadow = false
				end
			end
				
				
				


				
			end
		end
	end
end
end

result:


I try To add Debounce To Script But Continue Getting All In Magnitude
i Dont Know If It Possible

I didn’t quite understand what is your objective, do you want the bus to only pass through a single character? The closest to your player, perhaps? Or what exactly you mean?

Which two variables are the characters you’re trying to get the magnitude of?

Yes, I Want Magnitude Get The Closest Character

I Use To Get Torso And Humanoid ,I made if Is A Model And Find Humanoid In Model And Them I Made torso and humanoid

Would something like this work:

function Ability ()
	if Tool.Parent.Name == "Backpack" then return end
	if debounce then return end
	if ispassive then return end
	if plr.Character.IsRag.Value then return end
	if plr.Character:FindFirstChild("CantAbility") then return end
	local human = plr.Character:FindFirstChildWhichIsA("Humanoid")
	
	local closest = nil
	local closestMag = math.huge
	
	for i,v in pairs(workspace:GetChildren()) do
		if v:IsA("Model") and v.Name ~= plr.Character.Name then
			if v:FindFirstChildWhichIsA("Humanoid") then
				if v:FindFirstChild("Invicible") or v.IsRag.Value then return end
				
				local mag = (plr.Character:FindFirstChild("Torso").Position - v:FindFirstChild("Torso").Position).Magnitude 
				
				if mag < closestMag then
					closestMag = mag
					closest = v
				end
			end
		end
	end
	
	if not closest then return end -- Just in case it doesn't find any players
	
	local humanoid = closest:FindFirstChildWhichIsA("Humanoid")
	local torso = closest:FindFirstChild("Torso")
	local pos = (plr.Character.Torso.Position - torso.Position)
	if pos.Magnitude <= 70 then
		debounce = true
		spawn(function()
			wait(22.6) --cooldown for fart wall
			debounce = false
		end)
		if game.Workspace:FindFirstChild(plr.UserId.."BUS+BUS") then
			game.Workspace:FindFirstChild(plr.UserId.."BUS+BUS"):Destroy()
		end

		local bus = game.ServerStorage.BusModel:Clone()
		bus.Parent = workspace
		bus.Script.Enabled = true
		bus.Name = plr.UserId.."BUS+BUS"
		local apart = Instance.new("Part",workspace)
		apart.CFrame = torso.CFrame * CFrame.new(0,5,200)
		monar(apart,0.1)
	end
end

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.