Still have questions? Join our Discord server and get real time help.
0

# How do I stop this Shift to sprint script from running when a specific item is unequipped?

I feel like I was too vague about my previous question.

What I'm trying to do is create a shift to sprint key for a gun I am working on. I have the script for the shift to sprint, but the problem is that the shift to sprint script still works after the item is unequipped. I have attempted to disable the script while the item is unequipped, but that just stops the script from running completely. I do not have much experience with scripting, so this is all new to me. Here is my script with the script.Disabled part.

Tool = script.Parent

Tool.Equipped:connect(function()
game:GetService("UserInputService").InputBegan:connect(function(input,gameprocesed)
if input.KeyCode == Enum.KeyCode.LeftShift then
for i = 1,16 do
wait()
game.Players.LocalPlayer.Character:WaitForChild("Humanoid").WalkSpeed = game.Players.LocalPlayer.Character:WaitForChild("Humanoid").WalkSpeed + 1
end
end
end)

game:GetService("UserInputService").InputEnded:connect(function(input,gameprocesed)
if input.KeyCode == Enum.KeyCode.LeftShift then
for i = 1,16 do
wait()
game.Players.LocalPlayer.Character:WaitForChild("Humanoid").WalkSpeed = game.Players.LocalPlayer.Character:WaitForChild("Humanoid").WalkSpeed - 1
end
end
end)

game.Players.LocalPlayer.Character:WaitForChild("Humanoid").Died:connect(function()
game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 16
script.Disabled = true
end)

Tool.Unequipped:connect(function()
game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 16
script.Disabled = true
end)
end)


Please give deep explanations while answering. I'm extremely new to this and would like some help understanding things like this.

0
Assuming the rest of your script works, you just need to add another "if" statement like "if tool then..[do stuff]..else..[don't do stuff].." ABK2017 391 — 5mo
0
How would you do the "don't do stuff" part? Wiredfpz 2 — 5mo