Here is my code:
local UserInputServise = game:GetService("UserInputService")
local Character = script.Parent.Parent.Parent.Character
local Humanoid = Character:WaitForChild("Humanoid")
local isRunning = false
local Animation = Humanoid:LoadAnimation(script:WaitForChild("Animation"))
local EventTwo = game.ReplicatedStorage.ButtonPressed
local Presses = 0
UserInputServise.InputBegan:Connect(function(key)
if key.KeyCode == Enum.KeyCode.T then
if not isRunning then
isRunning = true
Animation:Play()
Humanoid.WalkSpeed = 7
end
end
end)
UserInputServise.InputEnded:Connect(function(key)
if key.KeyCode == Enum.KeyCode.T then
isRunning = false
Animation:Stop()
Humanoid.WalkSpeed = 10
end
end)
None of the below is needed.
script.Parent.Equipped:Connect(function()
local EventOne = game.ReplicatedStorage.ShowGUI
EventOne:FireServer()
end)
script.Parent.Unequipped:Connect(function()
local EventOne = game.ReplicatedStorage.ShowGUI
EventOne:FireServer()
end)
EventTwo.OnServerEvent:Connect(function()
Presses = Presses + 1
if Presses == 1 then
if not isRunning then
isRunning = true
Animation:Play()
Humanoid.WalkSpeed = 7
end
else
if isRunning then
Presses = 0
isRunning = false
Animation:Stop()
Humanoid.WalkSpeed = 10
end
end
end)
The code is inside of a tool that will be inside of the players backpack when this code runs.