#help

13 messages · Page 1 of 1 (latest)

paper estuary
#

e

#
-- Insert your animation ID here
local ANIMATION_ID = "rbxassetid://17191900926"  -- Replace 123456789 with your animation ID

-- Function to play animation
local function playAnimation(character)
    local humanoid = character:FindFirstChildOfClass("Humanoid")
    if humanoid then
        local animation = Instance.new("Animation")
        animation.AnimationId = ANIMATION_ID
        local animationTrack = humanoid:LoadAnimation(animation)
        animationTrack:Play()
    end
end

-- Function to handle tool equipped event
local function onToolEquipped(tool)
    local character = tool.Parent
    if character and character:IsA("Model") and character:IsDescendantOf(game.Players) then
        playAnimation(character)
    end
end

-- Connect the tool equipped event to the handler function
game.Players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(character)
        character.ChildAdded:Connect(function(child)
            if child:IsA("Tool") then
                child.Equipped:Connect(function()
                    onToolEquipped(child)
                end)
            end
        end)
    end)
end)

Why doesn't this work?

#

Meant to look like this

shy wharf
#

animation priority before exporting to roblox

#

action4 or action3

cerulean wave
#

Hello! here is the fixed script if this doesnt work please let me know!

#
-- Insert your animation ID here
local ANIMATION_ID = "rbxassetid://17191900926"  -- Replace 123456789 with your animation ID

-- Function to play animation
local function playAnimation(character)
    local humanoid = character:FindFirstChildOfClass("Humanoid")
    if humanoid then
        local animation = Instance.new("Animation")
        animation.AnimationId = ANIMATION_ID
        local animationTrack = humanoid:LoadAnimation(animation)
        animationTrack:Play()
    end
end

-- Function to handle tool equipped event
local function onToolEquipped(tool)
    local character = tool.Parent
    if character and character:IsA("Model") and character:IsDescendantOf(game.Players.LocalPlayer) then
        playAnimation(character)
    end
end

-- Connect the tool equipped event to the handler function
game.Players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(character)
        character.ChildAdded:Connect(function(child)
            if child:IsA("Tool") then
                child.Equipped:Connect(function()
                    onToolEquipped(child)
                end)
            end
        end)
    end)
end)

Changes made:

  1. Replaced game.Players with game.Players.LocalPlayer in onToolEquipped function to ensure it only works for the local player's character.
  2. Corrected the check for character:IsDescendantOf(game.Players.LocalPlayer) to make sure it's the character of the local player.

With these changes, the script should now correctly play the animation when the local player equips a tool. Make sure to replace ANIMATION_ID with the actual ID of your animation.

#

@paper estuary

paper estuary
#
-- Insert your animation ID here
local 17191900926 = "rbxassetid://17191900926"  -- Replace 123456789 with your animation ID

-- Function to play animation
local function playAnimation(character)
    local humanoid = character:FindFirstChildOfClass("Humanoid")
    if humanoid then
        local animation = Instance.new("Animation")
        animation.AnimationId = 17191900926
        local animationTrack = humanoid:LoadAnimation(animation)
        animationTrack:Play()
    end
end

-- Function to handle tool equipped event
local function onToolEquipped(tool)
    local character = tool.Parent
    if character and character:IsA("Model") and character:IsDescendantOf(game.Players.LocalPlayer) then
        playAnimation(character)
    end
end

-- Connect the tool equipped event to the handler function
game.Players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(character)
        character.ChildAdded:Connect(function(child)
            if child:IsA("Tool") then
                child.Equipped:Connect(function()
                    onToolEquipped(child)
                end)
            end
        end)
    end)
end)

@cerulean wave

patent ploverBOT
#

studio** You are now Level 1! **studio

paper estuary
#

cheers mee6

#

Question should i just be a script file?