You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve? Keep it simple and clear!
I need help with fixing all the lag issues in my game, I’m not asking for complete code, I’m just asking for what the issues are and how to help it. -
What is the issue? Include screenshots / videos if possible!
Basically there are 2 main issues, whenever I kill a player or npc in my game, the entire client and server pauses and makes my gpu fans go up. Another issue is when I equip the weapons in the game, the game will pause in the client for like 2-5 seconds (it only happens when I have viewmodels enabled). -
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I’ve tried to just optimise as much as I can but I don’t have much knowledge on optimising games.
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
Server code for hitting the player
local push = function(dir,p)
local Vele = Instance.new("BodyVelocity",p)
Vele.MaxForce = Vector3.new(1,1,1) * math.huge
Vele.Velocity = dir*10
debris:AddItem(Vele,.1)
end
local hitPlayer = function(piece,damage,dir,origin,pos,character,p)
table.insert(character,piece.Parent)
for i,v in pairs(workspace.walls:GetChildren()) do
table.insert(character,v)
end
for i,v in pairs(workspace.doors:GetChildren()) do
table.insert(character,v)
end
for i,v in pairs(workspace:GetChildren()) do
if not v:FindFirstChildWhichIsA("Humanoid") then continue end
for _,b in pairs(v:GetChildren()) do
if not b:IsA("Accessory") then continue end
table.insert(character,b)
end
end
for i,v in pairs(workspace.rappel:GetChildren()) do
if not v:IsA("BasePart") then continue end
for _, b in pairs(v:WaitForChild("window"):GetChildren()) do
if not v:IsA("BasePart") then continue end
table.insert(character,b)
end
end
if piece.Name == "Head" then
piece.Parent:FindFirstChildWhichIsA("Humanoid"):TakeDamage(damage*10)
clientEvs.hit:FireClient(p,0,1)
elseif piece.Name ~= "Torso" and piece.Name ~= "HumanoidRootPart" then
piece.Parent:FindFirstChildWhichIsA("Humanoid"):TakeDamage(damage*.75)
clientEvs.hit:FireClient(p,0,0)
else
piece.Parent:FindFirstChildWhichIsA("Humanoid"):TakeDamage(damage)
clientEvs.hit:FireClient(p,0,0)
end
if piece.Parent:FindFirstChildWhichIsA("Humanoid") and piece.Parent:FindFirstChildWhichIsA("Humanoid").Health <= 0 then
push(dir,piece)
end
end
--in an event connect that is fired when the player gets a hit on the client
if hit then
if hit.Parent:IsA("Accessory") and hit.Parent.Parent:FindFirstChildWhichIsA("Humanoid") or hit.Parent:FindFirstChildWhichIsA("Humanoid") then
local filter = {}
hitPlayer(hit,realdamage,dir,origin,position,filter,p)
else
if hit.Anchored == false then
push(dir,hit)
end
end
end
this is the client code for the vms
local removeVM = function()
debrisGobbler:AddItem(vm,0)
animations = animationsTemp
vm = nil
end
local addVM = function(name)
if vm then
removeVM()
end
vm = game.ReplicatedStorage.VMS[name]:Clone()
aimVector = (vm.aimPart.Position-vm.HumanoidRootPart.Position)
aimVectorX = vm.aimPart.Position.X-vm.HumanoidRootPart.Position.X
vm.Parent = workspace.CurrentCamera
for _,v in pairs(vm:FindFirstChild("Animations"):GetChildren()) do
loadAnimation(v.AnimationId,v.Name,animations,vm.Humanoid)
end
end
-- this is in a renderstepped function
if game.Players.LocalPlayer.Character:FindFirstChildWhichIsA("Tool") then
if itemEquipped ~= game.Players.LocalPlayer.Character:FindFirstChildWhichIsA("Tool") then
itemEquipped = game.Players.LocalPlayer.Character:FindFirstChildWhichIsA("Tool")
addVM(itemEquipped.Name)
end
else
if itemEquipped then
itemEquipped = nil
removeVM()
end
end
if game.Players.LocalPlayer.Character.Humanoid.Health <= 0 then
removeVM()
ermWadda:Disconnect()
end
Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.
Thanks if you guys can help me at all because I really am sort of done with this at this point.