I was trying to make a Fireball that hits the nearest body.

The script:

local Bloom1 = game:GetService("ServerStorage").Bloom1

local Bloom1Speed = 100
local Bloom1Lifetime = 5
local Bloom1Damage = 16
local hitbox = 5
local Bloom1cooldown = 0
local canshoot = true
function findTorsoNearest(position)
	local list = workspace.Zombie:GetChildren()
	local filteredlist = {}
	for _, v in pairs(list) do
		if game.Players:GetPlayerFromCharacter(v) == nil and v:FindFirstChild("Humanoid") then
			table.insert(filteredlist, v.Torso)
		end
	end
	local ClosestTorso = nil
	local Distance = nil
	for _, v in pairs(filteredlist) do
		if Distance == nil then
			Distance = (v.Position - position).magnitude
			ClosestTorso = v.Torso
			continue
		elseif  (v.Position - position).magnitude < Distance then
			ClosestTorso = v.Torso
			Distance = (v.Position - position).magnitude
		end
	end
	return ClosestTorso
end
script.Parent.Fire.OnServerEvent:Connect(function(player)
	if not canshoot then return end
	canshoot = false
	**local closestTorso = findTorsoNearest((script.Parent.CFrame * CFrame.new(0, 0, -5)).p)**
	local root = player.Character.HumanoidRootPart
	local fb = Bloom1:Clone()
	fb.CFrame = root.CFrame
	local rocketpropal = Instance.new("RocketPropulsion")
	rocketpropal.CartoonFactor = 1
	rocketpropal.TargetRadius = hitbox
	rocketpropal.MaxSpeed = Bloom1Speed
	rocketpropal.MaxTorque = Vector3.new(40,40,0)
	rocketpropal.MaxThrust = 5000
	rocketpropal.ThrustP = Bloom1Speed
	rocketpropal.ThrustD = 0.5
	rocketpropal.Target = closestTorso
	rocketpropal.Parent = fb
	fb.Parent = workspace
	rocketpropal:Fire()
	local alreadyhit = false
	rocketpropal.ReachedTarget:Connect(function()
		closestTorso.Parent.Humanoid:TakeDamage(Bloom1Damage)
		fb:Destroy()
	end)
	game.Debris:AddItem(fb, Bloom1Damage)
	delay(Bloom1cooldown, function() canshoot = true end)
end)

The error is in the title... what to do?

Bloom1 -- is a fireball. Zombie is a file.

8 comments

0

Please sort your code correctly using the Lua Button when typing a message.

0

I'll try haha-

0

done

0

Provide us with the code line, also have you heard of printing to debug

0

34

0

do player.HumanoidRootPart.CFrame

0

you mean like- replace fFindTorsoNearest with player.HumanoidRootPart.CFrame? Or what

0

"CFrame is not valid member of localscript" means its trying to find the CFrame of your localscript, its impossible. Try to see if youre not trying to find the CFrame of the localscript by accident instead of a character part.