"local Player = game.Players.LocalPlayer local Character = Player.Character or…
- User
"local Player = game.Players.LocalPlayer local Character = Player.Character or Player.CharacterAdded:Wait() local Humanoid = Character.Humanoid local HRP = Character.HumanoidRootPart local Camera = workspace.CurrentCamera local gun = Player.Backpack:WaitForChild("Tool")
local UIS = game:GetService("UserInputService") local RS = game:GetService("RunService") local GuiService = game:GetService("GuiService") local TS = game:GetService("TweenService") local ReplicatedStorage = game:GetService("ReplicatedStorage") local DeployedVm = Camera:WaitForChild("GunViewmodel")
local Animations = { ["Idle"] = }
local function OnEquipped() local Viewmodel = ReplicatedStorage.v_blanktemplate:Clone() Viewmodel.Parent = Camera Viewmodel.Name = "GunViewmodel" Animations.Idle:Play{}
for _, part in ipairs(Viewmodel:GetDescendants()) do if part:IsA("BasePart") then part.CanCollide = false part:SetAttribute("CollisionGroupId", 0) end end
RS:BindToRenderStep("Viewmodel",301, function(DT) Viewmodel:PivotTo( Camera.CFrame ) end) end
local function OnUnequipped() local Viewmodel = Camera:FindFirstChild("GunViewmodel") if Viewmodel then Viewmodel:Destroy() end end
gun.Equipped:Connect(OnEquipped) gun.Unequipped:Connect(OnUnequipped)" How do i make the viewmodel play an animation when it spawns
- Assistant
To make the viewmodel play an animation when it spawns, you can add the animation to the "OnEquipped" function. Here is an example of how you can do this:
local function OnEquipped() local Viewmodel = ReplicatedStorage.v_blanktemplate:Clone() Viewmodel.Parent = Camera Viewmodel.Name = "GunViewmodel"
-- Play the animation here local Animation = Instance.new("Animation") Animation.AnimationId = "rbxassetid://1234567890" -- replace with the animation ID local AnimationTrack = Humanoid:LoadAnimation(Animation) AnimationTrack:Play() for _, part in ipairs(Viewmodel:GetDescendants()) do if part:IsA("BasePart") then part.CanCollide = false part:SetAttribute("CollisionGroupId", 0) end end RS:BindToRenderStep("Viewmodel", 301, function(DT) Viewmodel:PivotTo( Camera.CFrame ) end)end
You can replace "rbxassetid://1234567890" with the ID of the animation you want to play. Make sure to add the animation to ReplicatedStorage so it can be loaded using the AnimationId property.
- User
how do i make the animation loop?
- Assistant
To make the animation loop, you can set the
Loopedproperty of theAnimationTracktotrue. Here is the modified code:local function OnEquipped() local Viewmodel = ReplicatedStorage.v_blanktemplate:Clone() Viewmodel.Parent = Camera Viewmodel.Name = "GunViewmodel" -- Play the animation here local Animation = Instance.new("Animation") Animation.AnimationId = "rbxassetid://1234567890" -- replace with the animation ID local AnimationTrack = Humanoid:LoadAnimation(Animation) AnimationTrack.Looped = true -- set Looped to true to make the animation loop AnimationTrack:Play() for _, part in ipairs(Viewmodel:GetDescendants()) do if part:IsA("BasePart") then part.CanCollide = false part:SetAttribute("CollisionGroupId", 0) end end RS:BindToRenderStep("Viewmodel", 301, function(DT) Viewmodel:PivotTo( Camera.CFrame ) end) endNow the animation will loop continuously until the
AnimationTrackis stopped. - User
How do i make the animation play faster?
- Assistant
To make the animation play faster, you can adjust the
PlaybackSpeedproperty of theAnimationTrack. Here is an example of how you can do this:local function OnEquipped() local Viewmodel = ReplicatedStorage.v_blanktemplate:Clone() Viewmodel.Parent = Camera Viewmodel.Name = "GunViewmodel" -- Play the animation here local Animation = Instance.new("Animation") Animation.AnimationId = "rbxassetid://1234567890" -- replace with the animation ID local AnimationTrack = Humanoid:LoadAnimation(Animation) AnimationTrack.Looped = true AnimationTrack.PlaybackSpeed = 2 -- set the PlaybackSpeed to 2 to make the animation play twice as fast AnimationTrack:Play() for _, part in ipairs(Viewmodel:GetDescendants()) do if part:IsA("BasePart") then part.CanCollide = false part:SetAttribute("CollisionGroupId", 0) end end RS:BindToRenderStep("Viewmodel", 301, function(DT) Viewmodel:PivotTo( Camera.CFrame ) end) endYou can adjust the
PlaybackSpeedvalue to make the animation play at your desired speed. A value of1means the animation will play at the default speed, while a value greater than will make the animation play faster. - User
how do i make the animation preload?
- Assistant
To preload the animation, you can use the
AnimationController:LoadAnimationmethod to load the animation into memory before it is needed. Here is an example of how you can do this:local function OnEquipped() local Viewmodel = ReplicatedStorage.v_blanktemplate:Clone() Viewmodel.Parent = Camera Viewmodel.Name = "GunViewmodel" -- Preload the animation here local Animation = Instance.new("Animation") Animation.AnimationId = "rbxassetid://1234567890" -- replace with the animation ID local AnimationController = Humanoid:LoadAnimation(Animation) AnimationController:LoadAsync() -- Play the animation here local AnimationTrack = AnimationController:LoadAnimation(Animation) AnimationTrack.Looped = true AnimationTrack.PlaybackSpeed = 2 AnimationTrack:Play() for _, part in ipairs(Viewmodel:GetDescendants()) do if part:IsA("BasePart") then part.CanCollide = false part:SetAttribute("CollisionGroupId", 0) end end RS:BindToRenderStep("Viewmodel", 301, function(DT) Viewmodel:PivotTo( Camera.CFrame ) end) end - User
AnimationController:LoadAsync() is not a real atribbute to a animation
- Assistant
I apologize for the mistake in my previous response.
LoadAsyncis not an attribute of an animation or an animation controller. Instead, you can use theContentProvider:Preloadmethod to preload the animation assets. Here is an example of how you can do this:-- preload the animation assets local function PreloadAnimation(animationId) local asset = "rbxassetid://" .. tostring(animationId) game:GetService("ContentProvider"):PreloadAsync({ asset }) end local function OnEquipped() local Viewmodel = ReplicatedStorage.v_blanktemplate:Clone() Viewmodel.Parent = Camera Viewmodel.Name = "GunViewmodel" -- Preload the animation here local Animation = Instance.new("Animation") Animation.AnimationId = "rbxassetid://1234567890" -- replace with the animation ID PreloadAnimation(Animation.AnimationId) -- Play the animation here local AnimationTrack = Humanoid:LoadAnimation(Animation) AnimationTrack.Looped = true AnimationTrack.PlaybackSpeed = 2 AnimationTrack:Play() for _, part in ipairs(Viewmodel:GetDescendants()) do if part:IsA("BasePart") then part.CanCollide = false part:SetAttribute("CollisionGroupId", 0) end end RS:BindToRenderStep("Viewmodel", 301, function(DT) Viewmodel:PivotTo(Camera.CFrame) end) end