What do you want to achieve?
I want to take the player’s ability to press shift (which is made for sprint) to keep the tiger sitting and not moving while sitting. The walkspeed in the script works as intened, if you press R the tiger sits and can’t move and when you press R again the tiger stands up and you have normal walkspeed (9 in this case).
What is the issue?
The problem is that when the player presses shift, the tiger changes its walkspeed to 40 which is the new sprint speed and I don’t want the shift key to change the walkspeed during this animation because the tiger is able to move while sitting which I want to avoid.
What solutions have you tried so far?
I asked in servers, looked on the devforum and watched yt videos but unfortunately I wasn’t able to find something useful.
That’s my code for the sitting animation!
local keyPressed = Enum.KeyCode.R
local animationId = "7615701980"
local userInputService = game:GetService("UserInputService")
local player = game:GetService("Players").LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://"..animationId
local animationTrack = humanoid:LoadAnimation(animation)
userInputService.InputBegan:Connect(function(input,isTyping)
if isTyping then return end
if input.KeyCode == keyPressed then
if not animationTrack.IsPlaying then
animationTrack:Play()
humanoid.WalkSpeed = 0
else
humanoid.WalkSpeed = 9
animationTrack:Stop()
end
end
end)```
local UserInputService = game:GetService("UserInputService")
local Players = game:GetService("Players")
local localPlayer = Players.LocalPlayer
UserInputService.InputBegan:Connect(function(input, gameProccesed, IsTyping)
if gameProccesed and IsTyping then
return
else
if input.KeyCode == Enum.KeyCode.LeftShift then
humanoid = localPlayer.Character:WaitForChild("Humanoid")
humanoid.WalkSpeed = 40
local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://7599350562"
animation.Parent = humanoid
loadedAnimation = humanoid:LoadAnimation(animation)
loadedAnimation:Play()
end
end
end)
UserInputService.InputEnded:Connect(function(input, gameProccesed, IsTyping)
if gameProccesed and IsTyping then
return
else
if input.KeyCode == Enum.KeyCode.LeftShift then
humanoid.WalkSpeed = 9
loadedAnimation:Stop()
end
end
end)```
Yeah the script is ignoring the other one, and whenever you press shift it starts sprinting, in the sprinting script add a check to see if it’s sitting, if it isnt then it can sprint
if input.KeyCode == Enum.KeyCode.LeftShift and not sitting then
-- All of the sprinting stuff, walkspeed, animations
end
Edit: Keep in mind you need to have “sitting” in the script
local UserInputService = game:GetService("UserInputService")
local Players = game:GetService("Players")
local localPlayer = Players.LocalPlayer
local RDown = UserInputService:GetKeysPressed(Enum.KeyCode.R)
UserInputService.InputBegan:Connect(function(input, gameProccesed, IsTyping)
if gameProccesed and IsTyping and RDown == true then
return
else```
The rDown
local keyPressed = Enum.KeyCode.R
local animationId = "7615701980"
local userInputService = game:GetService("UserInputService")
local player = game:GetService("Players").LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://"..animationId
local animationTrack = humanoid:LoadAnimation(animation)
local sitting = false
userInputService.InputBegan:Connect(function(input, gameProccesed, isTyping)
if isTyping then return end
if input.KeyCode == keyPressed then
if not animationTrack.IsPlaying then
animationTrack:Play()
humanoid.WalkSpeed = 0
sitting = true
else
humanoid.WalkSpeed = 9
animationTrack:Stop()
sitting = false
end
end
if gameProccesed and isTyping then
return
else
if input.KeyCode == Enum.KeyCode.LeftShift and not sitting then
humanoid = player.Character:WaitForChild("Humanoid")
humanoid.player = 40
local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://7599350562"
animation.Parent = humanoid
loadedAnimation = humanoid:LoadAnimation(animation)
loadedAnimation:Play()
end
end
end)
userInputService.InputEnded:Connect(function(input, gameProccesed, IsTyping)
if gameProccesed and IsTyping then
return
else
if input.KeyCode == Enum.KeyCode.LeftShift then
humanoid.WalkSpeed = 9
loadedAnimation:Stop()
end
end
end)```
Its both scripts in one, haven't tested it
This happens because the sprint animation overrides the other animation
You can check if the animation is playing by using the IsPlaying property.
if animationTrack.IsPlaying then return end
how it would look like:
--it might contain errors, i think you can fix them alone
local animationId = "7615701980"
local UserInputService = game:GetService("UserInputService")
local Players = game:GetService("Players")
local localPlayer = Players.LocalPlayer
humanoid = localPlayer.Character:WaitForChild("Humanoid")
local animationTrack = humanoid:LoadAnimation(animation)
UserInputService.InputBegan:Connect(function(input, gameProccesed, IsTyping)
if gameProccesed and IsTyping or animationTrack.IsPlaying then
return
end
if input.KeyCode ~= Enum.KeyCode.LeftShift then return end
input.KeyCode == Enum.KeyCode.LeftShift
humanoid.WalkSpeed = 40
local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://7599350562"
animation.Parent = humanoid
loadedAnimation = humanoid:LoadAnimation(animation)
loadedAnimation:Play()
end)
UserInputService.InputEnded:Connect(function(input, gameProccesed, IsTyping)
if gameProccesed and IsTyping or animationTrack.IsPlaying then
return
end
if input.KeyCode ~= Enum.KeyCode.LeftShift then return end
humanoid.WalkSpeed = 9
loadedAnimation:Stop()
end)