Wait Problem with Dash

I’ve made a dash and i need to delay loop but its fps based , i’ve tried everything but nothing works…

here’s code:

		local Velocity = Instance.new("BodyVelocity", Character.PrimaryPart)

		Velocity.MaxForce = Vector3.new(1000000, 0, 1000000)

		for i = 85, 16, -1 do
			if Direction == "Back" then
				Velocity.Velocity = Character.PrimaryPart.CFrame.LookVector * -i
			elseif Direction == "Right" then
				Velocity.Velocity = Character.PrimaryPart.CFrame.RightVector * i
			elseif Direction == "Left" then
				Velocity.Velocity = Character.PrimaryPart.CFrame.RightVector * -i
			end

                    wait (0.007)
		end

		Velocity:Destroy()
7 Likes

i tried tick() i tried heartbeat , nothing

5 Likes

What exactly is the problem? What do you want to achieve?

2 Likes

Have you considered using DeltaTime? It should make it work better

4 Likes

also wait(0.007) won’t work because there is a limit to how small it can wait (approx 0.3, this is also the default btw)

2 Likes

Works for me…

game:GetService("Players").PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character)
		wait(5)
		local Direction = "Back"
		local Velocity = Instance.new("BodyVelocity", Character.PrimaryPart)

		Velocity.MaxForce = Vector3.new(1000000, 0, 1000000)

		for i = 85, 16, -1 do

			if Direction == "Back" then
				Velocity.Velocity = Character.PrimaryPart.CFrame.LookVector * -i
			elseif Direction == "Right" then
				Velocity.Velocity = Character.PrimaryPart.CFrame.RightVector * i
			elseif Direction == "Left" then
				Velocity.Velocity = Character.PrimaryPart.CFrame.RightVector * -i
			end

			print(i, Direction, Velocity.Velocity)

			wait (0.007)
		end

		Velocity:Destroy()	
	end)
end)

Wait has the minimum limit of 0.03 seconds btw. If put any lower or no value at all, it will use 0.03.

5 Likes

Can you please show us where this part of code is nested. Is it inside of a RunService function?

3 Likes

its userinputservice.inputbegan

2 Likes

i need my value 0.3 is not for me

2 Likes

i want to make delay in my loop not based on fps

2 Likes

I just used the script you mentioned in your post.

2 Likes

Why would you even need a value so negligible, just use task.wait 1/60, you’re not able to go under it anyways. However there is one other thing you could try though, you could use RunService.Hearbeat:Wait() I’d say this is what you’re looking for. Ask me if you have any issues.

3 Likes

nothing you said works , i need dash like this

2 Likes

Yeah but what does your current code do wrong

4 Likes

task.wait(0.007) might help
it doesnt depend on fps

2 Likes

task.wait()

there is no reason to get precise delay because almost everything runs within the time of 1/60 seconds

2 Likes

This dash gets slowed overtime with the use of the RunService.Heartbeat function, Here is some code for a dash that gets slowed overtime and doesnt depend on FPS:

-- [[ Settings ]] --
local Dash_Speed = 100; -- Change this to your liking
local Dash_Duration = 0.7; -- Change this to your liking
local Dash_Range = 0.15;

-- [[ Variables ]] --
local Lifetime = 0.15;
local LookVector = HumanoidRootPart.CFrame.LookVector; -- Change this

local BV = Instance.new'BodyVelocity';
BV.MaxForce = Vector3.new(50000, 0, 50000);
BV.Velocity = LookVector * Dash_Speed;
Debris:AddItem(BV, Dash_Duration);

task.delay(Dash_Duration - Lifetime, function()
    
    local Con;

    Con = RunService.Heartbeat:Connect(function(DT)
        Lifetime -= DT;

        if BV == nil or BV and BV.Parent == nil then Con:Disconnect(); Con = nil; end
        if Lifetime <= 0 and Con ~= nil then Con:Disconnect(); Con = nil; end
        
        local Decrease_Rate = 0.15; -- Adjust to your liking
        local Velocity = (Lifetime * Dash_Speed) / Decrease_Rate;
        
        Velocity = math.clamp(Velocity, 0, Velocity);

        BV.Velocity = Velocity;
    end)
end)

This still depends on your fps or tps, If the player ever freezes their frames for extended times, force is applied and physically simulated also based on deltaTime

If you want something to consistently complete the same result, you need to define a start and end position

the clip that was sent does the same thing that my script does, theres no need for further stuff in my opinion, thats what he asked for, also it does support fps??

1 Like

Yeah they are the same, I was just pointing out they still depend on fps/tps