Hello, this is a part of my FPS framework, Drop and holster functions (server side)
local function Drop(tool)
wait(0.1)
print(game.ReplicatedStorage.LunarWeaponary.ViewModels:GetChildren())
local drop = game.ReplicatedStorage.LunarWeaponary.ViewModels["v_"..tool.Name]:Clone()
print(drop)
for i,v in pairs(drop:GetChildren()) do
if v.Name == "Left Arm" then
v:Destroy()
elseif v.Name == "Right Arm" then
v:Destroy()
elseif v.Name == "HumanoidRootPart" then
v:Destroy()
end
end
for i,v in pairs(drop:GetChildren()) do
spawn(function()
v.CollisionGroup = "Default"
v.CanCollide = true
v.CanQuery = true
v.Massless = false
end)
end
drop.PrimaryPart = drop.Grip
player.Character:WaitForChild("Remove"):FireClient(player,tool)
drop.Parent = workspace
drop:SetPrimaryPartCFrame(player.Character.Torso.CFrame * CFrame.new(Vector3.new(0,0,-2)))
drop.Grip.Velocity = player.Character.Torso.CFrame.lookVector * 20
print("Dropped")
end
local function Holster(plr,tool)
for i,v in pairs(plr.Character.Holsters:GetChildren()) do
if v.Name == tool.Name then
v:Destroy()
end
end
local drop
if plr.Character:FindFirstChild("v_"..tool.Name) then
local var = plr.Character["v_"..tool.Name]:Clone()
drop = var.Handle.Gun
else
drop = game.ReplicatedStorage.LunarWeaponary.ViewModels["v_"..tool.Name]:Clone()
end
print(drop)
for i,v in pairs(drop:GetChildren()) do
if v.Name == "Left Arm" then
v:Destroy()
elseif v.Name == "Right Arm" then
v:Destroy()
elseif v.Name == "HumanoidRootPart" then
v:Destroy()
end
end
local weld = Instance.new("WeldConstraint")
drop.PrimaryPart = drop.Grip
drop:SetPrimaryPartCFrame(player.Character.Torso.CFrame * CFrame.new(Vector3.new(0.5,0,0.6)) * CFrame.Angles(math.rad(-90),math.rad(45),math.rad(90)))
weld.Parent = drop
weld.Part0 = drop.PrimaryPart
weld.Part1 = player.Character.HumanoidRootPart
drop.Parent = plr.Character.Holsters
drop.Name = tool.Name
svm:Destroy()
end
the problem is that whenever i drop or holster the weapon the game lags
if anyone have any idea how to make it less laggy please let me know, any help is appreciated