#ANIMATION wont play (Noob to scripts)

2 messages · Page 1 of 1 (latest)

river dune
#

Like ive had this problem so long now and cant fix it
This is the main code that is inside of the TOOL

-- Place this script in the Tool object.
local Tool = script.Parent -- The tool this script is inside of
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")

local ViewmodelFolderName = "Viewmodels" -- Name of the folder in ReplicatedStorage
local ViewmodelName = "ButterflyViewmodel" -- Name of the viewmodel

local player = Players.LocalPlayer
local camera = workspace.CurrentCamera
local viewmodel

-- Function to setup and display the viewmodel
local function showViewmodel()
    local folder = ReplicatedStorage:FindFirstChild(ViewmodelFolderName)
    if not folder then
        warn("Folder not found in ReplicatedStorage: " .. ViewmodelFolderName)
        return
    end

    local viewmodelTemplate = folder:FindFirstChild(ViewmodelName)
    if not viewmodelTemplate then
        warn("Viewmodel not found in folder: " .. ViewmodelFolderName)
        return
    end

    viewmodel = viewmodelTemplate:Clone()
    viewmodel.Parent = workspace -- Parent to workspace to make it visible

    local cameraBone = viewmodel:FindFirstChild("CameraBone")
    if not cameraBone then
        warn("CameraBone not found in viewmodel: " .. ViewmodelName)
        return
    end

    -- Update viewmodel position and orientation each frame
    RunService.RenderStepped:Connect(function()
        if viewmodel and camera then
            cameraBone.CFrame = camera.CFrame
        end
    end)
end

-- Function to hide the viewmodel
local function hideViewmodel()
    if viewmodel then
        viewmodel:Destroy()
        viewmodel = nil
    end
end

-- Tool equipped and unequipped events
Tool.Equipped:Connect(showViewmodel)
Tool.Unequipped:Connect(hideViewmodel)
#

And this is the animation one

local AnimCtrl = script.Parent.AnimationController --your position of animctrler

local Anim = script.Animation --add one and put id in it

AnimCtrl.Animator:LoadAnimation(Anim):Play()