So currently, I’m working on my fps game, and i got a script from the youtube channel “NightTime Developments”, and I tried asking how to play animations for the viewmodel on their discord, but i wasn’t given much information. The script is:
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local camera = game.Workspace.CurrentCamera
local aimCF = CFrame.new()
local isAiming = false
local framework = {
inventory = {
"XM4";
"Glock";
"Knife";
"Grenade";
};
module = nil;
viewmodel = nil;
}
local anims = game.ReplicatedStorage.Animations
local viewmodels = game.ReplicatedStorage.Viewmodels
function loadSlot(Item)
local viewmodelFolder = game.ReplicatedStorage.Viewmodels
local moduleFolder = game.ReplicatedStorage.Modules
if moduleFolder:FindFirstChild(Item) then
framework.module = require(moduleFolder:FindFirstChild(Item))
if viewmodelFolder:FindFirstChild(Item) then
framework.viewmodel = viewmodelFolder:FindFirstChild(Item):Clone()
framework.viewmodel.Parent = camera
end
end
end
RunService.RenderStepped:Connect(function()
for i, v in pairs(camera:GetChildren()) do
if v:IsA("Model") then
v:SetPrimaryPartCFrame(camera.CFrame * aimCF)
end
end
if isAiming and framework.viewmodel ~= nil then
local offset = framework.viewmodel.AimPart.CFrame:ToObjectSpace(framework.viewmodel.PrimaryPart.CFrame)
aimCF = aimCF:Lerp(offset, 0.1)
else
local offset = CFrame.new()
aimCF = aimCF:Lerp(offset, 0.1)
end
end)
loadSlot(framework.inventory[1])
UserInputService.InputBegan:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseButton2 then
isAiming = true
UserInputService.MouseIconEnabled = false
end
end)
UserInputService.InputEnded:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseButton2 then
isAiming = false
UserInputService.MouseIconEnabled = true
end
end)
I’ve also tried playing the animations in a localscript but it doesn’t work. Any help would be greatly appreciated.