The issue with this is that I get a big lag spike when ever I equip the weapon.
I have asked multiple people for help and tried different ways of going for this but still no luck.
function module:Equip(name)
if CurrentWeapon and CurrentWeaponSettings then
CurrentWeapon:Destroy()
CurrentWeaponSettings = nil
CurrentWeapon = nil
end
if not WeaponSwitchingDebounce then
WeaponSwitchingDebounce = true
local weapon = FrameworkFolder.Viewmodels:FindFirstChild(name):Clone()
CurrentWeaponSettings = require(FrameworkFolder.Modules.Weapon:FindFirstChild(name.."Setup"))
CurrentWeapon = weapon
CurrentWeapon.Parent = Camera
waitTime(.25)
WeaponSwitchingDebounce = false
end
end
Can you please provide the Weapon module? The problem maybe the Setup function or it may happen when you clone your Viewmodels because high amount of meshes.
This is inside of the local script I am using (the equip function is in a module)
-----------------------------------
repeat wait() until game:IsLoaded()
-----------------------------------
-----------------------------------
local Player = game.Players.LocalPlayer
local Character = game.Players.LocalPlayer.Character
local Humanoid = game.Players.LocalPlayer.Character.Humanoid
-----------------------------------
-----------------------------------
local ReplicatedStorage = game.ReplicatedStorage
local IndigoFolder = game.ReplicatedStorage.Indigo
local FrameworkFolder = game.ReplicatedStorage.Indigo.Framework
-----------------------------------
-----------------------------------
local UserInputService = game:GetService("UserInputService")
local ContextActionService = game:GetService("ContextActionService")
local RunService = game:GetService("RunService")
-----------------------------------
-----------------------------------
local Shared = require(script.SharedScripts)
local Indigo = require(FrameworkFolder.Modules.Used.IndigoEngine)
-----------------------------------
-----------------------------------
UserInputService.InputBegan:Connect(function(key)
if key.KeyCode == Enum.KeyCode.One then
Indigo:Equip(Shared.Loadout.Primary)
end
end)
RunService.RenderStepped:Connect(function()
Indigo:Update()
end)
I think instead of cloning, you can change it parent and then change it back. And make sure change it on Client side so glitch won’t happen for everyone
I just tried that and still a lag spike. I really have no clue what could be causing this. (Updated code):
function module:Equip(name)
if CurrentWeapon then
CurrentWeapon.Parent = FrameworkFolder.Viewmodels
CurrentWeapon = nil
CurrentWeaponSettings = nil
end
local weapon = FrameworkFolder.Viewmodels:FindFirstChild(name)
CurrentWeaponSettings = require(FrameworkFolder.Modules.Weapon:FindFirstChild(name.."Setup"))
CurrentWeapon = weapon
CurrentWeapon.Parent = Camera
end
Alright so the lag spike is not as severe as it was, but its still noticeable. I have had this issue for around a year now. I still do not know why this is happening.