Why is my NPC going super fast after doing an attack?

so, ive been trying to make a bossfight for a game and im making a 3 part attack (minos prime reference) and after it does that, it tries to clip into the floor (which i have a separate script stopping it from doing)
and once it gets saved, it starts going at hypersonic speeds
attacks function (the char is the character to target and the distance is the distance from the NPC’s hrp to the character’s hrp)

function multiattacks(char,distance)
	chatservice:Chat(fhead,"PREPARE YOURSELF!")
	local velocity = char.HumanoidRootPart.AssemblyLinearVelocity --tried to set velocities to see if thatd fix anything. it didnt
	velocity = Vector3.new(velocity.X,0,velocity.Z)
	local fvelocity = fhrp.AssemblyLinearVelocity
	fvelocity = Vector3.new(velocity.X,0,fvelocity.Z)
	if fvelocity.X > 10 then
		fvelocity = Vector3.new(10,0,fvelocity.Z)
	end
	if fvelocity.Z > 10 then
		fvelocity = Vector3.new(fvelocity.X,0,10)
	end
	if fvelocity.X < -10 then
		fvelocity = Vector3.new(-10,0,fvelocity.Z)
	end
	if fvelocity.Z < -10 then
		fvelocity = Vector3.new(fvelocity.X,0,-10)
	end
	local anim = Instance.new("Animation")
	anim.AnimationId = "http://www.roblox.com/asset/?id=16092779469"
	local animtrack = fhum:LoadAnimation(anim)
	animtrack:Play()
	local cancel = false
	repeat
		wait()
		if math.round(animtrack.TimePosition*10)/10 == 0.2 and teleportdebounce == false and distance < 1000 then
			print("YES YES YEEEEEEEES")
			fhrp.CFrame = CFrame.lookAt(fhrp.Position,char.HumanoidRootPart.Position + velocity) 
			fhrp.Position = char.HumanoidRootPart.Position + velocity
			fhrp.Touched:Connect(function(hit)
				if hit.Parent:FindFirstChildOfClass("Humanoid") and hit.Parent.Name ~= "Fungrita" and hit.Parent.Name ~= "Mushroom Track" and hit.Parent.Name ~= "Mushroom Follow" and hit.Parent.Name ~= "True Mushroom" then
					local humanoid = hit.Parent:FindFirstChildOfClass("Humanoid")
					humanoid:TakeDamage(20)
					knockback(fhrp,hit.Parent)
				end
			end)
			task.spawn(function()
				teleportdebounce = true
				wait(0.1)
				print("teleport debounce reset")
				teleportdebounce = false
			end)
		end

		if math.round(animtrack.TimePosition*10)/10 == 1.1 and teleportdebounce == false and distance < 1000 then
			fhrp.CFrame = CFrame.lookAt(fhrp.Position,char.HumanoidRootPart.Position + velocity) 
			fhrp.Position = char.HumanoidRootPart.Position + velocity
			fhrp.Touched:Connect(function(hit)
				if hit.Parent:FindFirstChildOfClass("Humanoid") and hit.Parent.Name ~= "Fungrita" and hit.Parent.Name ~= "Mushroom Track" and hit.Parent.Name ~= "Mushroom Follow" and hit.Parent.Name ~= "True Mushroom" then
					local humanoid = hit.Parent:FindFirstChildOfClass("Humanoid")
					humanoid:TakeDamage(20)
					knockback(fhrp,hit.Parent)
				end
			end)
			task.spawn(function()
				teleportdebounce = true
				wait(0.1)
				teleportdebounce = false
			end)
		end

		if math.round(animtrack.TimePosition*10)/10 == 2.1 and teleportdebounce == false and distance < 1000 then
			fhrp.CFrame = CFrame.lookAt(fhrp.Position,char.HumanoidRootPart.Position + velocity) 
			fhrp.Position = char.HumanoidRootPart.Position + velocity
			local sound = Instance.new("Sound")
			sound.SoundId = "rbxassetid://3802269741"
			sound.Parent = fhrp
			sound.Volume = 2
			sound:Play()
			game.Debris:AddItem(sound,3)
			local newshockwave = game.ServerStorage.Shockwave:Clone()
			newshockwave.Position = Vector3.new(fhrp.Position.X,1.5,fhrp.Position.Z)
			newshockwave.Parent = workspace
			task.spawn(function()
				teleportdebounce = true
				wait(0.1)
				teleportdebounce = false
			end)
			task.spawn(function()
				local tweeninfo = TweenInfo.new(3)
				local goal = {}
				goal.Size = Vector3.new(1.5,180,180)
				goal.Transparency = 1
				local tween = tweenservice:Create(newshockwave,tweeninfo,goal)
				tween:Play()
				newshockwave.Touched:Connect(function(hit)
					if hit.Parent:FindFirstChildOfClass("Humanoid") and hit.Parent.Name ~= "Fungrita" and hit.Parent.Name ~= "Mushroom Track" and hit.Parent.Name ~= "Mushroom Follow" and hit.Parent.Name ~= "True Mushroom" then
						local humanoid = hit.Parent:FindFirstChildOfClass("Humanoid")
						if stompiframe == false then
							humanoid:TakeDamage(30)
							knockback(newshockwave,hit.Parent)
							task.spawn(function()
								stompiframe = true
								wait(1)
								stompiframe = false
							end)
						end
					end
				end)
				tween.Completed:Connect(function()
					newshockwave:Destroy()
				end)
			end)
		end
		animtrack.Ended:Connect(function()
			print("ended")
			cancel = true
			return
		end)
	until
	cancel == true
end

video (skip near to the end):

1 Like

Maybe it this causing an issue.

local velocity = char.HumanoidRootPart.AssemblyLinearVelocity
velocity = Vector3.new(velocity.X, 0, velocity.Z)

You aren’t using fvelocity there like you are in the rest of it idk if you did that intentionally.

In the second line, you are creating a new Vector3 with the X component from velocity and the Z component from the original fvelocity . This effectively replaces the Y component of fvelocity with the X component of velocity . If this is not your intention, it could result in incorrect or unintended values for the Y component of fvelocity .

1 Like