Fireball Stutter

I’ve made a fireball script following a guide but after using it for a little bit it starts to freeze mid way then it’ll continue. Not too sure what to do I’ve been messing around with it but I can’t get it to fix.

Here’s the code

local rp = game:GetService("ReplicatedStorage")
local fireball = rp:WaitForChild("Fireball")
local debris = game:GetService("Debris")

local meshes = script.Parent.Parent.ServerStorage:WaitForChild("Meshes")


fireball.OnServerEvent:Connect(function(Player)
	local char = Player.Character
	local humanoid = char:WaitForChild("Humanoid")
	local humrp = char:WaitForChild("HumanoidRootPart")
	
	

	
	local fireballmain = meshes:WaitForChild("FireballMain"):Clone()
	fireballmain.CFrame = humrp.CFrame * CFrame.new(0,0,-3)
	fireballmain.Parent = workspace
	
	local fireballout = meshes:WaitForChild("FireballOut"):Clone()
	fireballout.CFrame = fireballmain.CFrame
	fireballout.Parent = workspace
	
	local weld = Instance.new("WeldConstraint")
	weld.Parent = fireballmain
	weld.Part0 = fireballout
	weld.Part1 = fireballmain

	
	debris:AddItem(fireballmain, 2)
	debris:AddItem(fireballout, 2)

	
	
		
	local vel = Instance.new("BodyVelocity",fireballmain)
	vel.MaxForce = Vector3.new(5000,5000,5000) * 3000
	vel.Velocity = humrp.CFrame.lookVector * 100
	
	
end)

Just out of curiosity, try changing this

local vel = Instance.new("BodyVelocity",fireballmain)
	vel.MaxForce = Vector3.new(5000,5000,5000) * 3000
	vel.Velocity = humrp.CFrame.lookVector * 100

To this

local vel = Instance.new("BodyVelocity")
	vel.MaxForce = Vector3.new(5000,5000,5000) * 3000
	vel.Velocity = humrp.CFrame.lookVector * 100
	vel.Parent = fireballmain

Parenting an instance before defining/changing it’s properties is bad practice because A) its inefficient and B) can, in some cases, cause stuttering as seen above

Edit: Also change

local weld = Instance.new("WeldConstraint")
	weld.Parent = fireballmain
	weld.Part0 = fireballout
	weld.Part1 = fireballmain

to

local weld = Instance.new("WeldConstraint")
	weld.Part0 = fireballout
	weld.Part1 = fireballmain
	weld.Parent = fireballmain

Hey thanks for the reply I’ve changed all of the problem with parenting but it still seems to be doing it.

1 Like

Try setting the network owner

Network Ownership (roblox.com)

Usually works for things like this.

2 Likes

Good point. @Ocuay, try this:

local rp = game:GetService("ReplicatedStorage")
local fireball = rp:WaitForChild("Fireball")
local debris = game:GetService("Debris")

local meshes = script.Parent.Parent.ServerStorage:WaitForChild("Meshes")


fireball.OnServerEvent:Connect(function(Player)
	local char = Player.Character
	local humanoid = char:WaitForChild("Humanoid")
	local humrp = char:WaitForChild("HumanoidRootPart")
	
	local fireballmain = meshes:Clone()
	fireballmain.CFrame = humrp.CFrame * CFrame.new(0,0,-3)

	local fireballout = meshes:WaitForChild("FireballOut"):Clone()
	fireballout.CFrame = fireballmain.CFrame
	fireballout.Parent = workspace

	local weld = Instance.new("WeldConstraint")
	weld.Parent = fireballmain
	weld.Part0 = fireballout
	weld.Part1 = fireballmain


	debris:AddItem(fireballmain, 2)
	debris:AddItem(fireballout, 2)

	local vel = Instance.new("BodyVelocity")
	vel.MaxForce = Vector3.new(5000,5000,5000) * 3000
	vel.Velocity = humrp.CFrame.lookVector * 100
	
	fireballmain.Parent = workspace
	fireballout.Parent = workspace
	
	vel.Parent = fireballmain
	
	fireballmain:SetNetworkOwner(nil)
	fireballout:SetNetworkOwner(nil)

end)
1 Like

Ty this seems to have fixed the problem!

1 Like

Ty for the help seems to have fixed it

Sounds good, good luck in the future with other vfx :happy1:

1 Like