script:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local viewModels = ReplicatedStorage:WaitForChild("fpsViewModels"):GetChildren();
local cam = workspace.Camera
local UIS = game:GetService("UserInputService")
local RunService = game:GetService("RunService")
local IdleAnimation = Instance.new("Animation")
IdleAnimation.AnimationId = "rbxassetid://7120507317"
local currentWeapon
local currentIndex
local viewModelHumanoid
local function Equip(p_int)
viewModels[p_int]:SetPrimaryPartCFrame(cam.CFrame * CFrame.new(0,0,0.5))
currentIndex = p_int
currentWeapon = viewModels[currentIndex]
viewModelHumanoid = currentWeapon:WaitForChild("Humanoid")
local AnimationTrack = viewModelHumanoid:LoadAnimation(IdleAnimation)
AnimationTrack:Play()
currentWeapon.Parent = workspace
end
RunService.RenderStepped:Connect(function()
for i = 1,#viewModels do
Equip(i)
end
end)
UIS.InputBegan:Connect(function(Input)
if currentWeapon == workspace then
if Input.UserInputType == Enum.UserInputType.MouseButton1 then
print("Punching")
end
end
end)
The function Equip()
loads a new animation into your humanoid. You are calling this function hundreds of times per second with this part of the script:
RunService.RenderStepped:Connect(function()
for i = 1,#viewModels do
Equip(i)
end
end)
This causes a heavy overload in the animator because tracks are being added faster than they are being removed. I suggest that you don’t use RenderStepped here.
It’s always a good idea to load the animation globally and then play it. You don’t need to load a new one every time you play it.
put local AnimationTrack = viewModelHumanoid:LoadAnimation(IdleAnimation)
outside of the function so the error won’t come
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.