Automatic Walk speed?

Hello Developers
I’m not good at coding when it comes to non-ui. but my problem here is, how do i sync the walkspeed with the loading part? To elaborate more, here’s a video

As you can see, at first it’s perfect walkspeed. but at the end, i fell. i tried to make walk speed higher such as 17, 18, 18.5, 18.75, and 20 but in any time longer, i will fall as the same as 16 walk speed.

Original Script
local LastPos = Vector3.new(8.5, 0.5, -0.125)
local starting = false
local blockcount = 0
local start
start = script.Parent['0'].Touched:Connect(function()
	starting = true
	start:Disconnect()
end)
while true do
	if starting then
		blockcount += 1
		local block = script.Parent['block']:Clone()
		block.Name = blockcount
	block.Transparency = 1
	block.Position = LastPos+Vector3.new(5,-5,0)
	block.Parent = workspace
	LastPos += Vector3.new(5,0,0)
	game:GetService('TweenService'):Create(block,TweenInfo.new(0.5),{Position=block.Position+Vector3.new(0,5,0);Transparency=0}):Play()
		if script.Parent:FindFirstChild(blockcount-10) then
			game:GetService('TweenService'):Create(script.Parent:FindFirstChild(blockcount-10),TweenInfo.new(0.5),{Position=script.Parent:FindFirstChild(blockcount-10).Position-Vector3.new(0,5,0);Transparency=1}):Play()
		end
		if script.Parent:FindFirstChild(blockcount-11) then
			script.Parent:FindFirstChild(blockcount-11):Destroy()
		end
	end
	wait(0.25)
end	

I’ve tried

using Touched function but it just adds multiple block at the same time then it won’t work anymore.

Touched Function Script
local LastPos = Vector3.new(8.5, 0.5, -0.125)
local starting = false
local blockcount = 1
local start
start = script.Parent[blockcount-1].Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild('Humanoid') then
		blockcount += 1
		local block = script.Parent['block']:Clone()
		block.Name = blockcount
		block.Transparency = 1
		block.Position = LastPos+Vector3.new(5,-5,0)
		block.Parent = workspace
		LastPos += Vector3.new(5,0,0)
		game:GetService('TweenService'):Create(block,TweenInfo.new(0.5),{Position=block.Position+Vector3.new(0,5,0);Transparency=0}):Play()
		if script.Parent:FindFirstChild(blockcount-10) then
			game:GetService('TweenService'):Create(script.Parent:FindFirstChild(blockcount-10),TweenInfo.new(0.5),{Position=script.Parent:FindFirstChild(blockcount-10).Position-Vector3.new(0,5,0);Transparency=1}):Play()
		end
		if script.Parent:FindFirstChild(blockcount-11) then
			script.Parent:FindFirstChild(blockcount-11):Destroy()
		end
	end
end)

If this is just an animation consider tweening the character along the path instead

like what though? MoveTo? or just tweening the HumanoidRootPart?

the humanoidrootpart
make sure its the cframe property youre tweening though

well it won’t do an animation if it’s Humanoid root part so that’s my problem. it will just do falling animation or idle

Instead of trying to alter the players walkspeed, change the wait in the function to perfectly match their walkspeed.
You can calculate how long it should take for you to spawn a new block using the basic formula for speed.
speed = distance/time
Rearrange this to find the time and you can throw it into your loop.
time = distance/speed
I’d probably use RunService.Stepped instead of a while loop.
You should be able to make this work with any walkspeed you want by simply editing the equation at the end.

local RunService = game:GetService("RunService")
local TweenService = game:GetService("TweenService")
local LastPos = Vector3.new(8.5, 0.5, -0.125)
local starting = false
local blockcount = 0
local start
start = script.Parent['0'].Touched:Connect(function()
	starting = true
	start:Disconnect()
end)

local nextTime = 0
RunService.Stepped:Connect(function(Time, dt) 
	if starting and Time >= nextTime then
		blockcount += 1
		local block = script.Parent['block']:Clone()
		block.Name = blockcount
		block.Transparency = 1
		block.Position = LastPos+Vector3.new(5,-5,0)
		block.Parent = workspace
		LastPos += Vector3.new(5,0,0)
		TweenService:Create(block,TweenInfo.new(0.5),{Position=block.Position+Vector3.new(0,5,0);Transparency=0}):Play()
		if script.Parent:FindFirstChild(blockcount-10) then
			TweenService:Create(script.Parent:FindFirstChild(blockcount-10),TweenInfo.new(0.5),{Position=script.Parent:FindFirstChild(blockcount-10).Position-Vector3.new(0,5,0);Transparency=1}):Play()
		end
		if script.Parent:FindFirstChild(blockcount-11) then
			script.Parent:FindFirstChild(blockcount-11):Destroy()
		end
		nextTime = Time + (5/16) -- time = distance / speed
		--I assumed the size of a block would be 5 studs and that you're using the default walkspeed of 16
	end
end)
1 Like
local run = game:GetService("RunService")
local tweens = game:GetService("TweenService")
local debris = game:GetService("Debris")

local players = game:GetService("Players")
local player = players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local hrp = character:WaitForChild("HumanoidRootPart")
local humanoid = character:WaitForChild("Humanoid")

task.wait(1)

local nextTime = 0

run.Stepped:Connect(function(totalTime, stepTime)
	if totalTime > nextTime then
		local part = Instance.new("Part")
		part.TopSurface = Enum.SurfaceType.Smooth
		part.BrickColor = BrickColor.Random()
		part.Anchored = true
		part.Size = Vector3.new(6, 2, 8)
		part.CFrame = hrp.CFrame + Vector3.new(0, -7, 0)
		part.Transparency = 1
		part.Parent = workspace
		local tween = tweens:Create(part, TweenInfo.new(0.1, Enum.EasingStyle.Linear), {Position = part.Position + Vector3.new(0, 3, 0), Transparency = 0})
		tween:Play()
		debris:AddItem(part, 3)
		nextTime = totalTime + (part.Size.Z/2)/humanoid.WalkSpeed
	end
end)

I know this is resolved I just wanted to write a script for it.

1 Like