so ive noticed in the game im scripting for, whenever a player is equipping the tool (katana) or slashing with the weapon and they die (either by reset or killed by someone) the ping spikes for everyone in the server, aka server lag. does anyone have any idea whats going on and possible fixes/workarounds?
Would you like to show some code?
alright so ive done some debugging and narrowed it down to this piece of code thats fired when the character dies (it spawns a replacement sword that drops to the ground when the player dies)
ReplicatedStorage:WaitForChild("spawnDeadSword").OnServerEvent:Connect(function(player, character, handle)
if player == Players:GetPlayerFromCharacter(script.Parent.Parent) or player == script.Parent.Parent.Parent then
if not character:FindFirstChild("deadSword") then
local deadSword = handle:Clone()
deadSword.Name = "deadSword"
deadSword.Parent = character
deadSword.Position = handle.Position
deadSword.Orientation = handle.Orientation
deadSword.CanCollide = true
handle.CanCollide = true
end
end
end)
does anything seem off here?
1 Like
so i’ve figured it out. the problem was that when the “handle” was cloned, the descendants of it was also cloned and that was causing lag. to fix this, i cleared the descendants of “handle” before cloning it with “handle:ClearAllChildren()”
1 Like