I know that you can change the default animations with the animate script Roblox provides. But i don’t know how would i have different idle/walk when the character has a gun equipped instead of a knife?, Can someone give an example on how i would do this.
To create different default animations for different tools or weapons in Roblox, you’ll need to modify the Animate
script that’s included in the character model. Here’s a step-by-step example to achieve this, allowing your character to have different idle and walk animations depending on whether they have a gun or a knife equipped.
here is an example for the script
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local animateScript = character:WaitForChild("Animate")
-- Animation IDs
local defaultIdleAnim = "rbxassetid://12345678" -- Default idle
local defaultWalkAnim = "rbxassetid://87654321" -- Default walk
local gunIdleAnim = "rbxassetid://23456789" -- Gun idle
local gunWalkAnim = "rbxassetid://98765432" -- Gun walk
local knifeIdleAnim = "rbxassetid://34567890" -- Knife idle
local knifeWalkAnim = "rbxassetid://09876543" -- Knife walk
-- Function to update animations
local function updateAnimations(toolName)
if toolName == "Gun" then
animateScript.idle.Animation1.AnimationId = gunIdleAnim
animateScript.walk.WalkAnim.AnimationId = gunWalkAnim
elseif toolName == "Knife" then
animateScript.idle.Animation1.AnimationId = knifeIdleAnim
animateScript.walk.WalkAnim.AnimationId = knifeWalkAnim
else
-- Reset to default animations
animateScript.idle.Animation1.AnimationId = defaultIdleAnim
animateScript.walk.WalkAnim.AnimationId = defaultWalkAnim
end
end
-- Listen for tool equipped and unequipped
local function onToolEquipped(tool)
if tool:IsA("Tool") then
updateAnimations(tool.Name)
end
end
local function onToolUnequipped()
updateAnimations(nil) -- Reset to default animations
end
-- Connect to tool events
character.ChildAdded:Connect(function(child)
if child:IsA("Tool") then
child.Equipped:Connect(function() onToolEquipped(child) end)
child.Unequipped:Connect(onToolUnequipped)
end
end)
1 Like
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.