Boss keeps dashing without cooldown

so i was coding a dash for my boss so you cant just damage him forever,
here is the script, (i want him to dash every 8 to 25 seconds)

		task.spawn(function()
			while true do
				wait(math.random(8,25))
				dashAnim:Play()
				dashAnim.Priority = Enum.AnimationPriority.Action4
				game:GetService("SoundService").dash:Play()
				local back = Vector3.new(0,0,-3)
				local up = Vector3.new(0,-3,0)
				local bv = Instance.new("BodyVelocity", hrp)
				bv.Name = "Knockback"
				bv.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
				bv.Velocity = hrp.CFrame.LookVector * 45 + back + up
				game.Debris:AddItem(bv,.25)
			end
		end)

but this happens…

https://streamable.com/co3xar

as seen in the video he keeps dashing, why? (i cant seem to figure out the error in the code)

13 Likes

You’re using task.spawn. The task.spawn function will break through any task.wait()'s, especially if this is inside of a loop such as RunService.Heartbeat, while true do, for loop, etc. Try swapping places with the while true do loop and adding the task.spawn function inside it or any other methods you might know of. My specialty in coding is definitely not functions like these, but I can tell you that your task.spawn function is definitely the cause of it.

4 Likes

But I think he is using task.spawn() because he wants to do other stuff after the loop.
But, yes, he should use spawn() instead

3 Likes

Okay i will try to swap their places thanks

2 Likes

Wait no no because i have some code after this, the while true do will stop the code from progressing i think

1 Like

Maybe because you’re using incorrect statements.

There are 2 types of options you can do:

Option 1

You can convert task.spawn to spawn()

spawn(function()
			while true do
				wait(math.random(8,25))
				dashAnim:Play()
				dashAnim.Priority = Enum.AnimationPriority.Action4
				game:GetService("SoundService").dash:Play()
				local back = Vector3.new(0,0,-3)
				local up = Vector3.new(0,-3,0)
				local bv = Instance.new("BodyVelocity", hrp)
				bv.Name = "Knockback"
				bv.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
				bv.Velocity = hrp.CFrame.LookVector * 45 + back + up
				game.Debris:AddItem(bv,.25)
			end
		end)
Option 2

You can convert “true” to task.wait()

task.spawn(function()
			while task.wait() do
				wait(math.random(8,25))
				dashAnim:Play()
				dashAnim.Priority = Enum.AnimationPriority.Action4
				game:GetService("SoundService").dash:Play()
				local back = Vector3.new(0,0,-3)
				local up = Vector3.new(0,-3,0)
				local bv = Instance.new("BodyVelocity", hrp)
				bv.Name = "Knockback"
				bv.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
				bv.Velocity = hrp.CFrame.LookVector * 45 + back + up
				game.Debris:AddItem(bv,.25)
			end
		end)
1 Like

Im gonna try these, thanks you for the interest of helping !

Edit : Sorry but he stills keep dashing like in the video

1 Like

Maybe it could help if i post the whole code?

1 Like

Yes, please! It would help me understand better!

1 Like

Can you show me the part where he walks?
And also can you show me the part where he punches too? (By the video I’ve seen, I think that’s where he demolishes most of the parts)

Are you sure? Thats not very important for the dashing mechanic.

But then what’s the part where he dashes very time?

Note: I didn’t mean “demolishes”, I meant “dashes”

This is the part where he dashes (in the original message)

Can you show me the model of the boss? The parts
(like the torso for example)

Bcs I want to check something

May i know what do you want to check ? I dont feel confortable giving that much information and i dont think its revelant to the problem.

Then, does he have a Torso?
Note: It can be bcs of body collisions

He does have a torso, but i dont thats it because the sound and animations play, either way should i turn off torso collisions?

No, I mean like if the Body Parts (of the model) have CanCollide off/disabled/false.

It can be that. But it also can make the boss “look bad” (because you can go through the boss)

Yes thats what i was fearing. going though him will be bad

Isn’t there any other option in “AnimationPriority” that can be served/can be used for the animation? But for sure it isn’t because of that.

Now, another question: I’m not really good at BodyVelocities (I never used it or never talked about it) but does the MaxForce need to be all at INF?