Sprint local script not working in starter gui after respawn

  1. What do you want to achieve? Keep it simple and clear!
    I want to fix my local script in startergui, it doesn’t change the players walkspeed after they respawn

  2. What is the issue? Include screenshots / videos if possible!
    My local script doesn’t change the players walkspeed after they respawn

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I have tried YT and Devforum

Here is my code:

-- Variables

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local sprinting = false

player.CharacterAdded:Connect(function(newChar)
	character = newChar
	humanoid = newChar:WaitForChild("Humanoid")
end)

script.Parent.SprintButton.MouseButton1Click:Connect(function()
	if humanoid.Sit == false then
		if character:FindFirstChild("Arrested") then
			if character:FindFirstChild("Tased") then
				if character.Tased.Value == false then
					if character.Arrested.Value == false then
						if sprinting == false and humanoid.Sit == false then
							sprinting = true
							humanoid.WalkSpeed = 32
						end
					end
				end
			else
				if sprinting == false and humanoid.Sit == false then
					sprinting = true
					humanoid.WalkSpeed = 32
				end
			end
		else
			if sprinting == false and humanoid.Sit == false then
				sprinting = true
				humanoid.WalkSpeed = 32
			end
		end
	end

	if humanoid.Sit == false then
		if character:FindFirstChild("Tased") then
			if character.Tased.Value == false then
				if character:FindFirstChild("Arrested") then
					if character.Arrested.Value == false then
						if sprinting == true then
							sprinting = false
							player.Character.Humanoid.WalkSpeed = 16
						end
					end
				else
					if sprinting == true then
						sprinting = false
						player.Character.Humanoid.WalkSpeed = 16
					end
				end
			end
		end
	else
		if sprinting == true then
			sprinting = false
			player.Character.Humanoid.WalkSpeed = 16
		end
	end
end)
9 Likes

why is it in StarterGui? It should be in StarterPlayerScripts or StarterCharacterScripts.

7 Likes

Put the script in StarterPlayerScripts, therefore it is reset every time you spawn.

7 Likes

Hi!

I think I have a solution for ya.

Find the ScreenGui that is the parent of your Sprinting Gui and set ResetOnSpawn to false.

From what I understand, you’re trying to do sprinting with a button, but please make sure that it is sometimes inefficient to use buttons.

If the solution I provided doesn’t work for you, try placing your script in StarterCharacterScripts.

Have a nice one.

7 Likes

In the Explorer find the ScreenGui that your script is inside and make sure the property ResetOnSpawn is set to true

5 Likes

Johnny I see you everywhere :smiley:. You always answer with the correct idea! But I was faster this time :slight_smile:

6 Likes

Thanks, you type much quicker :grin:

6 Likes

I think you could use Humanoid.Died too, and because it is working with a button, I think it might be hard to put it into StarterPlayer/CharacterScripts.

Humanoid.Died:Connect(function()
sprinting = false
end)
4 Likes

I have guis that i need to use with the script

5 Likes

I have guis that i need to use with the script thats why

3 Likes

It is set to false

maximumcharacterlimit

3 Likes

All good guys, i fixed it myself doing something else

4 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.