What i’m picking up is when the player equips the tool, an animation will be on the player, upon unequipping it, the animation stops correct? If so simply do what I said above…
UserInputService.InputBegan:Connect(function(keyPressed, gameProcessed)
if gameProcessed then return end
if keyPressed.KeyCode = Enum.KeyCode.W then
Animation:Play()
repeat
wait()
until not UserInputService:IsKeyDown(Enum.KeyCode.W)
Animation:Stop()
end
end)
If the player is holding W, do the custom walk animation, if not holding, then don’t do the animation and the player will be idle.
No, that script doesnt work. (30 chars) You have to set the walk animation in a server script.
We want the player to walk like that until its unequipped, which also has to be set in a server script.
Holding W when the tool is equipped gives u the custom walk animation, basically. without the tool gives you the normal one. I’ll try it out,
This is what I normally used for the keys.
game:GetService("UserInputService").InputBegan:Connect(function(Input, gameProcessed)
if not gameProcessed then
if Input.KeyCode == Enum.KeyCode.W then
runtrack:Play()
print("walking")
end
end
end)
if script.Parent.Equipped == true then
game:GetService("UserInputService").InputEnded:Connect(function(Input, gameProcessed)
if not gameProcessed then
if Input.KeyCode == Enum.KeyCode.W then
runtrack:Stop()
Uh, you don’t even need that userinputservice then, you can just set the walk animation once the tool is equipped, and then just set the animation back to default once its unequipped.
-- Make sure it's in ServerScriptService (SSS)
game.Players.PlayerAdded:Connect(function(player)
local playertool = player:WaitForChild("Backpack"):WaitForChild("Bat"):WaitForChild("LocalScript") -- Change "Bat" to your tool name.
local Animation = Instance.new("Animation", playertool)
Animation.Name = "Run"
Animation.AnimationId = "rbxassetid://1234567890" --Change to Animation Id
end)
LocalScript
local player = game.Players.LocalPlayer
local tool = script.Parent -- Make sure the local script is inside of the tool.
local equipped = false
local Animation = script.Run -- Place animation inside of script.
local runtrack = plr.Character.Humanoid:LoadAnimation(Animation)
tool.Equipped:Connect(function()
equipped = true
end)
tool.Unequipped:Connect:(function()
equipped = false
end)
UserInputService.InputBegan:Connect(function(keyPressed, gameProcessed)
if gameProcessed then return end
if not equipped then return end
if keyPressed.KeyCode = Enum.KeyCode.W then
runtrack:Play()
repeat
wait()
until not UserInputService:IsKeyDown(Enum.KeyCode.W)
runtrack:Stop()
end
end)
The bool variable “equipped” lets us check if the weapon is equipped with
if not equipped then return end
basically saying, if the tool is not equipped, Don’t continue the following.
We set equipped when using
and then we just change it back to the default walk animation. Thats all we want, I already have a script thats working, and the script you sent failed.
If you change the AnimationPriority to Action, It most likely should not fail. If so what are the output errors.
EDIT: I also believe you can not redo setting the default walk animation, as they are owned by roblox and you can not set animations that are not owned by you or a group that your in.
Thank you! But the bat does not appear, here is the scripts.
local script:
local plr = game.Players.LocalPlayer
local tool = script.Parent -- Make sure the local script is inside of the tool.
local equipped = false
local Animation = script:WaitForChild("Run") -- Place animation inside of script.
local runtrack = plr.Character.Humanoid:LoadAnimation(Animation)
tool.Equipped:Connect(function()
equipped = true
end)
tool.Unequipped:Connect(function()
equipped = false
end)
game:GetService("UserInputService").InputBegan:Connect(function(keyPressed, gameProcessed)
if gameProcessed then return end
if not equipped then return end
if keyPressed.KeyCode == Enum.KeyCode.W then
runtrack:Play()
repeat
wait()
until not game:GetService("UserInputService"):IsKeyDown(Enum.KeyCode.W)
runtrack:Stop()
end
end)
serverscript:
game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(char)
local M6D = Instance.new("Motor6D", char.Torso)
M6D.Name = "ToolGrip"
end)
game.Players.PlayerAdded:Connect(function(player)
local playertool = player:WaitForChild("Backpack"):WaitForChild("Bat"):WaitForChild("LocalScript") -- Change "Bat" to your tool name.
local Animation = Instance.new("Animation", playertool)
Animation.Name = "Run"
Animation.AnimationId = "rbxassetid://5522791201" end)
end)