1 sprint script overiding other sprint scripts

  1. What do you want to achieve?
    Well, I don’t want the sprint script in the stamina bar, overriding the sprint scripts in my custom models.

  2. What is the issue?
    Imagine in the localscript in my custom model (tiger), I have a sprint script which causes the character to walk faster when holding shift. In this script the walkspeed is 8 and the sprint speed is 40. In the localscript in my other custom model (horse), the same system as above just the walkspeed is 9 and sprinting is 50. Now I got another sprint script in the stamina bar which appears when the player has chosen one of the animals above. The localscript in the stamina bar tho, contains it’s own speed of 16 walkspeed and let’s say 30 sprint speed. Now, when I spawn in and sprint with the tiger or horse, the localscript in the stamina bar changes the walkspeed and sprint speed of both animals to 16 and 30 which is obviously not the purpose because irl both of the animals have different speed. I don’t know how to fix that, like if there’s a possibility if I couldjust remove the variables for walk and sprint speed in the stamina bar script and replace them with the custom speeds for each animal.

  3. What solutions have you tried so far?
    Yt videos, servers and developer hub.

The script in the stamina bar, which overrides the speed I have determined in the localscripts in the models:

local UIS = game:GetService('UserInputService')
local Bool = game.ReplicatedStorage
local Sitting = Bool:WaitForChild("Sitting")
local Bar = script.Parent:WaitForChild('Background'):WaitForChild('Bar')

local player = game.Players.LocalPlayer


local NormalWalkSpeed = 9

local NewWalkSpeed = 40


local power = 10

local sprinting = false

repeat wait() until game.Players.LocalPlayer.Character



local character = player.Character

UIS.InputBegan:connect(function(key, gameProcessed)

	if key.KeyCode == Enum.KeyCode.LeftControl and gameProcessed == false  and Sitting.Value == false then

		character.Humanoid.WalkSpeed = NewWalkSpeed

		sprinting = true

		while power > 0 and sprinting do

			power = power - .015

			Bar:TweenSize(UDim2.new(power / 10, 0, 1, 0), 'Out', 'Quint', .1, true)

			--Bar.BackgroundColor3 = Bar.BackgroundColor3:lerp(Color3.fromRGB(255, 42, 42), 0.001)

			wait()

			if power <= 0 then

				character.Humanoid.WalkSpeed = NormalWalkSpeed

			end

		end

	end

end)



UIS.InputEnded:connect(function(key, gameProcessed)

	if key.KeyCode == Enum.KeyCode.LeftControl and gameProcessed == false and Sitting.Value == false then

		character.Humanoid.WalkSpeed = NormalWalkSpeed

		sprinting = false

		while power < 10 and not sprinting do

			power = power + .003

			Bar:TweenSize(UDim2.new(power / 10, 0, 1, 0), 'Out', 'Quint', .1, true)

			--Bar.BackgroundColor3 = Bar.BackgroundColor3:lerp(Color3.fromRGB(255, 166, 11), 0.001)

			wait()

			if power <= 0 then

				character.Humanoid.WalkSpeed = NormalWalkSpeed

			end

		end

	end

end)

An example script of the localscript in the tiger model:

local UIS = game:GetService('UserInputService')
local Bool = game.ReplicatedStorage
local Sitting = Bool:WaitForChild("Sitting")
local Bar = script.Parent:WaitForChild('Background'):WaitForChild('Bar')

local player = game.Players.LocalPlayer


local NormalWalkSpeed = 9

local NewWalkSpeed = 40


local power = 10

local sprinting = false

repeat wait() until game.Players.LocalPlayer.Character



local character = player.Character

UIS.InputBegan:connect(function(key, gameProcessed)

	if key.KeyCode == Enum.KeyCode.LeftControl and gameProcessed == false  and Sitting.Value == false then

		character.Humanoid.WalkSpeed = NewWalkSpeed

		sprinting = true

		while power > 0 and sprinting do

			power = power - .015

			Bar:TweenSize(UDim2.new(power / 10, 0, 1, 0), 'Out', 'Quint', .1, true)

			--Bar.BackgroundColor3 = Bar.BackgroundColor3:lerp(Color3.fromRGB(255, 42, 42), 0.001)

			wait()

			if power <= 0 then

				character.Humanoid.WalkSpeed = NormalWalkSpeed

			end

		end

	end

end)



UIS.InputEnded:connect(function(key, gameProcessed)

	if key.KeyCode == Enum.KeyCode.LeftControl and gameProcessed == false and Sitting.Value == false then

		character.Humanoid.WalkSpeed = NormalWalkSpeed

		sprinting = false

		while power < 10 and not sprinting do

			power = power + .003

			Bar:TweenSize(UDim2.new(power / 10, 0, 1, 0), 'Out', 'Quint', .1, true)

			--Bar.BackgroundColor3 = Bar.BackgroundColor3:lerp(Color3.fromRGB(255, 166, 11), 0.001)

			wait()

			if power <= 0 then

				character.Humanoid.WalkSpeed = NormalWalkSpeed

			end

		end

	end

end)```
2 Likes

Modulescripts.

You’ll also have to keep track of which animal the character is on and change the sprint speed accordingly.

1 Like