Whats wrong with my script? (sprint)

local Frame = script.Parent
local plr = game.Players.LocalPlayer
local char = plr.Character
local humanoid
if char then
	humanoid = char:FindFirstChildWhichIsA("Humanoid")
else
	char = plr.CharacterAdded:Wait()
	humanoid = char:FindFirstChildWhichIsA("Humanoid")
end
local speeds = Frame:WaitForChild("Speeds")
local event = Frame:WaitForChild("Speed")
local enabled = Frame:WaitForChild("Enabled")
local tired = false
local running = false
local moving = false
--------------------
--Config
local stamina = 250
local walk = speeds.Walk
local run = speeds.Run
local exhaust = speeds.Exhaust
--------------------

local function ChangeSpeed(spd)
	local char = plr.Character
	local humanoid
	if char then
		humanoid = char:FindFirstChildWhichIsA("Humanoid")
	end
	if humanoid.WalkSpeed ~= spd then -- Preventing remote spam.
		event:FireServer(1055299,spd)
	end
end

game:GetService("UserInputService").InputBegan:Connect(function(key)
	if key.KeyCode == Enum.KeyCode.LeftShift  and char:FindFirstChild("IsRunning").Value == true then
		if key.KeyCode == Enum.KeyCode.F then
			running = true
		end
	end
end)
game:GetService("UserInputService").InputEnded:Connect(function(key)
	if key.KeyCode == Enum.KeyCode.LeftShift then
		if key.KeyCode == Enum.KeyCode.LeftShift then
			char:FindFirstChild("IsRunning").Value = false
			running = false
		end
	end
end)

while wait() do
	if enabled.Value == true then
		if humanoid then
			if humanoid.MoveDirection == Vector3.new(0,0,0) then moving = false else moving = true end
			if tired then 
				ChangeSpeed(exhaust.Value) -- Rest
				Frame.Rest1.Visible = true
				Frame.Rest2.Visible = true
				if not moving then
					stamina = stamina + 1
				end
				if stamina > 0 then
					tired = false
					Frame.Rest1.Visible = false
					Frame.Rest2.Visible = false
					Frame.GreenBar:TweenSize(UDim2.new(3.5*stamina/875,0, 0,25), "Out", "Quad", 0.1, true)
				end
			elseif running == true then
				if moving then
					ChangeSpeed(run.Value) -- Sprint
					stamina = stamina - 1
					Frame.GreenBar:TweenSize(UDim2.new(3.5*stamina/875,0, 0,25), "Out", "Quad", 0.1, true)
					if stamina == 0 then tired = true stamina = -10 end
				elseif stamina < 250 then
					stamina = stamina + 1
					Frame.GreenBar:TweenSize(UDim2.new(3.5*stamina/875,0, 0,25), "Out", "Quad", 0.1, true)
				end
			else ChangeSpeed(walk.Value) -- Walk
				if not moving and stamina < 250 then
					stamina = stamina + 1
					Frame.GreenBar:TweenSize(UDim2.new(3.5*stamina/875,0, 0,25), "Out", "Quad", 0.1, true)
				end
			end
		end
	end
end

i get no errors but my walkspeed doesnt change even tho the bool value is set to true

I could be wrong here, but instead of doing

humanoid.MoveDirection == Vector3.new(0,0,0)

do

humanoid.MoveDirection.Magnitude <= 0

nope didnt work᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼

One question, is this being ran?

local function ChangeSpeed(spd)
	local char = plr.Character
	local humanoid
	if char then
		humanoid = char:FindFirstChildWhichIsA("Humanoid")
	end
	if humanoid.WalkSpeed ~= spd then -- Preventing remote spam.
		event:FireServer(1055299,spd)
	end
end

To my knowledge, both of those work.

1 Like

I haven’t looked into humanoid.MoveDirection other than humanoid.MoveDirection.Magnitude but yeah, you’re right.

1 Like

no it is not being ran ᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼

There’s either two things that are stopping this: the running boolean or the moving boolean. Can you check if either of those are true for me?

1 Like

sure thing ᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼

got rid of the bool value yet nothing changed, im thinking of using a script like this

local char = game.Players.LocalPlayer.Character
local hum = char:WaitForChild("Humanoid")
local anim1 = hum:LoadAnimation(script:WaitForChild("BlockAnim"))
local blockingval = char:WaitForChild("Sprint")

anim1:Play()
game:GetService("UserInputService").InputBegan:connect(function(input) 
	if input.KeyCode == Enum.KeyCode.LeftShift and char.IsRunning.Value == true then 
		anim1:Play()
		hum.WalkSpeed = 34
		script.Run1:Play()
		script.Run2:Play()
		
	end
end)

game:GetService("UserInputService").InputEnded:connect(function(input) 
	if input.KeyCode == Enum.KeyCode.LeftShift then
	char.isRunning.Value = false
		anim1:Stop()
		hum.WalkSpeed = 8
		wait(5)
		hum.WalkSpeed = 16
	end
end)

i tried this but like the other script no errors but it doesnt work

is char.IsRunning a value made by you? I think it’s just not running in my case.

1 Like

yes its a bool value which is parented to the player model

image

Final thing and I might have a solution…

Try turning that boolean on and disable any code that attempts to turn that boolean off.

1 Like

okay
᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼

didnt work sadly ᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼

I’m going to test your code, and I’m going to run results back to you in a few minutes.

1 Like

Okay so I tested your code, and your problem is that isRunning isn’t being turned on. Another problem might be is that somewhere in your full code, it might be a typo.

so i have another script which turns it on and even when i turn it on manually it still doesnt work