How do I get a range of numbers?

I wanna get a range of numbers that I can use so that I can see if the Humanoid is increasing in height or decreasing. This is so I can check if their rolling up or down a slope to increase their speed.

How would I be able to check this? Im already using RunService and saving the current humanoid root parts position every time Render Stepped Fires for a start.

	RunService.RenderStepped:Connect(function()
		local SavedPosition = HRP.Position
	end)

First, could you just check the velocity instead?

local isMovingUp = HRP.AssemblyLinearVelocity.Y > 0
if isMovingUp then
  print("up")
else
  print("down")
end

If not for some reason, just save the last one:

local last = HRP.Position
RunService.RenderStepped:Connect(function()
  local now = HRP.Position
  if now.Y > last.Y then
    print("up")
  else
    print("down")
  end
  last = now
end)
1 Like

I would recommend a change on the else because they could stand still and it would say going down.

elseif now.Y < last.Y then
1 Like

Thats a way simpler way to do it. Why didn’t I think of that.

I’ll try it.

So would this work?

UIS.InputBegan:Connect(function(input, gameProcessed)
	if humanoid.Running then
		if not gameProcessed and input == Enum.KeyCode.E then
			local RollBoost = Instance.new("LinearVelocity")
			RollBoost.MaxForce = 99999999999

			local Attatchment = Instance.new("Attachment")
			RollBoost.Attachment1 = Attatchment
			RollBoost.Attachment0 = Attatchment

			rollAnimTrack:Play()

			Attatchment.Parent = script.Parent:WaitForChild("HumanoidRootPart")

			local CurrentPosition = HRP.Position
			RunService.RenderStepped:Connect(function()
				local LivePosition = HRP.Position

				if LivePosition > CurrentPosition then
					RollBoost.VectorVelocity = HRP.CFrame.LookVector * 100
				elseif LivePosition < CurrentPosition then
					RollBoost.VectorVelocity = HRP.CFrame.LookVector * -50
				end
			end)
		end
	end
end)

No, you need to use the Y Vector of the Vector3.

UIS.InputBegan:Connect(function(input, gameProcessed)
	if humanoid.Running then
		if not gameProcessed and input == Enum.KeyCode.E then
			local RollBoost = Instance.new("LinearVelocity")
			RollBoost.MaxForce = 99999999999

			local Attatchment = Instance.new("Attachment")
			RollBoost.Attachment1 = Attatchment
			RollBoost.Attachment0 = Attatchment

			rollAnimTrack:Play()

			Attatchment.Parent = script.Parent:WaitForChild("HumanoidRootPart")

			local CurrentPosition = HRP.Position
			RunService.RenderStepped:Connect(function()
				local LivePosition = HRP.Position

				if LivePosition.Y > CurrentPosition.Y then
					RollBoost.VectorVelocity = HRP.CFrame.LookVector * 100
				elseif LivePosition.Y < CurrentPosition.Y then
					RollBoost.VectorVelocity = HRP.CFrame.LookVector * -50
				end
			end)
		end
	end
end)
1 Like

If you tap E twice then you’ll have two renderstep loops running at the same time which is probably not what you want.

Can you describe exactly what you want this code to do in detail? Like when exactly should it be setting the VectorVelocity? Does anything else mess with that?

I want it so that in realistic-ness, so when the player Rolls on the ground ( By pressing E ), they get a speed boost if their on ground that has its rotation 0,y,0, but if its on a part that is ( x, y, z ) in rotation ( or on the front or top of a wedge ), then it will get a speed boost depending if their going up or down.

Up = Less Speed

Down = More Speed.

@Kaid3n22 Sorry For Pinging

So Should I just check if E is being held, and how?

Oh, you would have a variable like this:

local holdingE = false

local RollBoost
local Attatchment
local CurrentPosition

UIS.InputBegan:Connect(function(input, gameProcessed)
	if humanoid.Running then
		if not gameProcessed and input == Enum.KeyCode.E then
			RollBoost = Instance.new("LinearVelocity")
			RollBoost.MaxForce = 99999999999

			Attatchment = Instance.new("Attachment")
			RollBoost.Attachment1 = Attatchment
			RollBoost.Attachment0 = Attatchment

			rollAnimTrack:Play()

			Attatchment.Parent = script.Parent:WaitForChild("HumanoidRootPart")

			CurrentPosition = HRP.Position

			holdingE = true
		end
	end
end)

UIS.InputEnded:Connect(function(key)
	if key.KeyCode == Enum.KeyCode.E then
		holdingE = false
		Attatchment:Destroy()
		RollBoost:Destroy()
		CurrentPosition = nil
	end
end)

RunService.RenderStepped:Connect(function()
	local LivePosition = HRP.Position

	if LivePosition.Y > CurrentPosition.Y then
		RollBoost.VectorVelocity = HRP.CFrame.LookVector * 100
	elseif LivePosition.Y < CurrentPosition.Y then
		RollBoost.VectorVelocity = HRP.CFrame.LookVector * -50
	end

	CurrentPosition = LivePosition
end)