I am making a running script, the problem is that the idle animation cannot be stopped
script not complete
player.CharacterAdded:connect(function(char)
WaitForCharacterLoad(char)
local mousedefault = true
UserInputService.InputBegan:Connect(function(input)
local Player = game.Players.LocalPlayer
local Character = Player.Character
local Anim = Instance.new('Animation')
Anim.AnimationId = 'rbxassetid://'
PlayAnim = Character.Humanoid:LoadAnimation(Anim)
UserInputService.InputBegan:connect(function(input)
if input.KeyCode == Enum.KeyCode.LeftShift then
UserInputService.MouseBehavior = Enum.MouseBehavior.LockCenter
GameSettings.RotationType = Enum.RotationType.MovementRelative
Character.Humanoid.WalkSpeed = 50
PlayAnim:Play()
end
end)
UserInputService.InputEnded:connect(function(input)
if input.KeyCode == Enum.KeyCode.LeftShift then
Character.Humanoid.WalkSpeed = 16
PlayAnim:Stop()
UserInputService.MouseBehavior = Enum.MouseBehavior.LockCenter
GameSettings.RotationType = Enum.RotationType.CameraRelative
end
end)
end)
end)
https://gyazo.com/c45d3b35d163e6805142cb3a68f2953f
1 Like
Is this a local script or a server script? Assuming this is not the full script, could you possibly show your full script? If its a local script, I dont see why the CharacterAdded event is in the script.
1 Like
I’m pretty sure animations on localscripts doesn’t show for everybody.
1 Like
Animations played from local scripts actually does show for everybody. Unless if you are playing an animation for an NPC, its probably best to play animations on local scripts
2 Likes
-- Is this in a local script?
player.CharacterAdded:connect(function(char)
WaitForCharacterLoad(char)
local mousedefault = true
local Player = game.Players.LocalPlayer
local Character = Player.Character
local Anim = Instance.new("Animation")
Anim.AnimationId = "rbxassetid://8128098622"
local PlayAnim = Character.Humanoid:LoadAnimation(Anim)
UserInputService.InputBegan:connect(function(input)
if input.KeyCode == Enum.KeyCode.LeftShift then
UserInputService.MouseBehavior = Enum.MouseBehavior.LockCenter
GameSettings.RotationType = Enum.RotationType.MovementRelative
Character.Humanoid.WalkSpeed = 50
PlayAnim:Play()
end
end)
UserInputService.InputEnded:connect(function(input)
if input.KeyCode == Enum.KeyCode.LeftShift then
Character.Humanoid.WalkSpeed = 16
PlayAnim:Stop()
UserInputService.MouseBehavior = Enum.MouseBehavior.LockCenter
GameSettings.RotationType = Enum.RotationType.CameraRelative
end
end)
end)
Please send the dev console error.
I don’t see any error in the console,
1 Like
Have you tried the code i sent?
yes , I’m not sure if it’s the animation
Is looped enabled on the animation?
yes i activate it, but I don’t understand why it doesn’t stop, I have other scripts with animation loop and it doesn’t bug. sorry i am using translator
1 Like
player.CharacterAdded:connect(function(char)
WaitForCharacterLoad(char)
local mousedefault = true
local Player = game.Players.LocalPlayer
local Character = Player.Character
local Anim = Instance.new("Animation", Character)
Anim.AnimationId = "rbxassetid://8128098622"
local PlayAnim = Character.Humanoid:LoadAnimation(Anim)
UserInputService.InputBegan:connect(function(input)
if input.KeyCode == Enum.KeyCode.LeftShift then
UserInputService.MouseBehavior = Enum.MouseBehavior.LockCenter
GameSettings.RotationType = Enum.RotationType.MovementRelative
Character.Humanoid.WalkSpeed = 50
PlayAnim:Play()
end
end)
UserInputService.InputEnded:connect(function(input)
if input.KeyCode == Enum.KeyCode.LeftShift then
Character.Humanoid.WalkSpeed = 16
PlayAnim:Stop()
UserInputService.MouseBehavior = Enum.MouseBehavior.LockCenter
GameSettings.RotationType = Enum.RotationType.CameraRelative
end
end)
end)
1 Like
Try now, I parented the animation to the character.
1 Like