Getting Speed Issue

Hey there!

Awhile ago I used a tutorial for my speed simulator type game for earning speed, and there was a setting for how fast you go. I went along with what it was saying thinking that if you add more to the value, you will earn speed faster, and the same if you lower it. But now, like months later, I went to go check that out, and I timed it, and it was actually the same!

The code:

local userIdString = string.sub(script.Name, 9)
local userId = tonumber(userIdString)
local player = game.Players:GetPlayerByUserId(userId)


local character = player.Character
local humanoid = character:WaitForChild("Humanoid")




local steps = player.Steps.Value
local speed = player.Speed.Value
local points = player.Points.Value
local trail = player.PlayerTrail.Value
--gives player the last saved speed
humanoid.WalkSpeed = speed

--used for tracking steps
local stepInterval = 0


-- constantly checks for the character's movement (runs every .05 seconds)
while true do
	--checks to make sure this is the right player
	if not player then
		script:Destroy()
	end
	
	--makes sure the player has a character in game
	if player.Character then
		
		local humanoid = player.character:WaitForChild("Humanoid")
		
		
		if ((humanoid.MoveDirection.x ~= 0) or (humanoid.MoveDirection.z ~= 0)) then
			--this number determines how quickly the character gains speed
			-- Make higher than 0.1 for faster speed increase, lower for slower
			stepInterval = stepInterval + 0.1
			if player.PlayerHasPassOtherStepGain.Value == true then
				stepInterval = stepInterval + 0.3
			end
			if player.PlayerHasPassStepGain.Value == true then
				stepInterval = stepInterval + 0.2
			end
			if player.PlayerPet.Value == "FoxPet" then
				stepInterval = stepInterval + 0.15
			end
			if player.PlayerPet.Value == "DeerPet" then
				stepInterval = stepInterval + 0.2
			end
			if player.PlayerPet.Value == "WaterDragonPet" then
				stepInterval = stepInterval + 0.3
			end
			if player.Name == "Player1" then
				stepInterval = stepInterval + 1
				print(stepInterval)
			elseif player.Name == "Player2" then
				stepInterval = stepInterval + 3
				print(stepInterval)
			end
		else
			stepInterval = 0
		end
		
		if (player.Steps.Value ~= steps) then
			steps = player.Steps.Value
		end
		
		--calculates the speed of steps
		if (stepInterval >= (5/speed)) then
			
			steps = steps + 1
			player.XP.Value = player.XP.Value + 1
			--calculates speed
			speed = math.floor(math.sqrt(steps/1.5)) + 1
			humanoid.WalkSpeed = speed
			stepInterval = 0
			
		end
		
		if (player.Points.Value ~= points) then
			points = player.Points.Value
		end
		
		player.Steps.Value = steps
		player.Points.Value = points
		player.Speed.Value = speed
	end
	local level = player:WaitForChild("Level")
	local MaxXp = level.Value * 250
	if player.XP.Value >= MaxXp then
		player.XP.Value = 0
		print(player.XP.Value)
		level.Value = level.Value + 1
		player.PlayerGui.SpeedGUI.LevelUpFrame.RemoteEvent:FireClient(player)
	end
	wait(0.05)
end --loop ends

From what I understand from the code, this doesn’t make sense, does anyone know why it took the same amount of time for example player1 (with 1 stepInterval) to earn speed as player2 (with 3 stepInterval)?

stepInterval is set back to zero a bunch; it’s used for tracking steps, not determining speed.

The comments say to change the constants to go faster:

2 Likes

Ok, so, I don’t know, but the step interval is only actually set back to 0 when the guy isn’t moving, or they earn a step. So I just noticed a couple days ago, it does make a difference if they are, let’s say one has 0.2 and the other has 0.5. So I am guessing once they are at a certain level it doesn’t make a difference. I am giving you da solution anyway just because you are the first to actually reply to me for this! Thanks!