My jojo game get a very high ping!

So, i tried to make a jojo game, this is my 2nd try so far the first one movements isn’t smooth so i tried changing it, but now on the 2nd Version. it lags.



as you can see, the Ping is very high. so that means it lags, right?
i tried my best to make it not lag, like making all the effects and tween in clients, making 1 Script in ServerScriptService to handle all the Damages,Projectile,Stand Movements,etc.
The 1 Script that Handles Everything:

local tab = {}
function refresh()
	tab = {}
	for i,v in pairs(workspace:GetDescendants()) do
		table.insert(tab,v)
	end
end
--[[workspace.DescendantAdded:Connect(function(child)
	refresh()
end)
workspace.DescendantRemoving:Connect(function(child)
	refresh()
end)
refresh()
function DEbuff(child,char)
	if child.Name == "Stunned" then
		local unstun = game.ServerStorage["Buffs/Debuff"].StopStunned:Clone()
		unstun.Parent = char
	end
end]]--

game:GetService("RunService").Heartbeat:Connect(function()
	for i,v in pairs(workspace:GetDescendants()) do
		--TimeStop--
		--[[if v:FindFirstChild("unTS") then
			v.unTS:Destroy()
			if v:FindFirstChild("TS") then
				v.TS:Destroy()
			end
			if v:IsA("Model") and v.PrimaryPart ~= nil then
				v.PrimaryPart.Anchored = false
				print(v.Name.." Anchored = false")
				if v:FindFirstChildWhichIsA("Humanoid") then
					for _,anim in pairs(v.Humanoid:GetPlayingAnimationTracks()) do
						anim:AdjustSpeed(1)
					end
					if v:FindFirstChild("ScriptFolder") then
						v.ScriptFolder:FindFirstChild(string.match(v.Name,"Input")).Disabled = false
					end
				end
			elseif v:IsA("Part") or v:IsA("MeshPart") or v:IsA("UnionOperation") then
				v.Anchored = false
				print(v.Name.." Anchored = false")
			end
		end
		if v:FindFirstChild("TS") then
			if v:IsA("Model") then
				v.PrimaryPart.Anchored = true
				if v:FindFirstChildWhichIsA("Humanoid") then
					for _,anim in pairs(v.Humanoid:GetPlayingAnimationTracks()) do
						anim:AdjustSpeed(0)
					end
					if v:FindFirstChild("ScriptFolder") then
						v.ScriptFolder:FindFirstChild(string.match(v.Name,"Input")).Disabled = true
					end
				end
			else
				v.Anchored = true
			end
		end]]--
		--Projectiles--
		if v:FindFirstChild("Projectile") then
			if v.Projectile:FindFirstChild("Position") then
				if not v:FindFirstChild("TS") then
				local direction = CFrame.new(v.Position,v.Projectile.Position.Value)
				local dist = (v.Position - v.Projectile.Position.Value).Magnitude
				if dist > (v.Projectile.Value/2 + 1) then
					v.Position = v.Position + (direction.LookVector * v.Projectile.Value)
				else
					v.Position = v.Projectile.Position.Value
				end
				end
			elseif v.Projectile:FindFirstChild("Target") then
				if not v:FindFirstChild("TS") then
				local direction = CFrame.new(v.Position,v.Projectile.Target.Value.Position)
				local dist = (v.Position - v.Projectile.Target.Value.Position).Magnitude
				if dist > (v.Projectile.Value/2) then
					v.Position = v.Position + (direction.LookVector * v.Projectile.Value)
				else
					v.Position = v.Projectile.Target.Value.Position
				end
				end
			else
				if not v:FindFirstChild("TS") then
				local direction = v.CFrame
				v.Position = v.Position + (direction.LookVector * v.Projectile.Value)
				end
			end
		end
		--CustomDebris--
		if v:FindFirstChild("CustomDebris") then
			if not v:FindFirstChild("TS") then
				if v.CustomDebris.Value > 0 then
					v.CustomDebris.Value = v.CustomDebris.Value - 0.18
				else
					v:Destroy()
				end
			end
		end
		--Debuffs--
		if v:FindFirstChildWhichIsA("Humanoid") and not v:FindFirstChild("DebuffCheck") then
			local check = Instance.new("BoolValue",v)
			check.Name = "DebuffCheck"
			local chcon
			chcon = v.ChildRemoved:Connect(function(child)
				if child.Name == "Stunned" then
					local unstun = game.ServerStorage["Buffs/Debuff"].StopStunned:Clone()
					unstun.Parent = v
				end
			end)
			local dscon
			dscon = v.Humanoid.Died:Connect(function()
				print(v.Name.."Died")
				chcon:Disconnect()
				dscon:Disconnect()
			end)
		end
		
		if v:FindFirstChildWhichIsA("Humanoid") and v:FindFirstChild("Stunned") then
			v.Humanoid:ChangeState(Enum.HumanoidStateType.Ragdoll)
		elseif v:FindFirstChildWhichIsA("Humanoid") and v:FindFirstChild("StopStunned") then
			v.Humanoid:ChangeState(Enum.HumanoidStateType.GettingUp)
			v.StopStunned:Destroy()
		end
		
		--Agility--
		if v:FindFirstChild("Humanoid") and v:FindFirstChild("Agility") then
			v.Humanoid.WalkSpeed = v.Agility.Value
		end
		
		--Damage Dealt--
		if v:FindFirstChild("DamageTaken") then
			if v.DamageTaken.Value > 0 and not v:FindFirstChild("TS") then
				v.Humanoid:TakeDamage(v.DamageTaken.Value)
				v.DamageTaken.Value = 0
			end
		end
		--Stand Follow--
		if v:FindFirstChild("aStand") then
			if v:FindFirstChild("Owner") and v:FindFirstChild("FollowCFrame") then
				if v.Owner.Value ~= nil then
					v:SetPrimaryPartCFrame(v.PrimaryPart.CFrame:lerp(v.Owner.Value.PrimaryPart.CFrame * v.FollowCFrame.Value,((v.PrimaryPart.Position - v.Owner.Value.PrimaryPart.Position).Magnitude/1000)*v.FollowCFrame.FollowSpeed.Value))
					if not workspace:FindFirstChild(v.Owner.Value.Name) or v.Owner.Value.Humanoid.Health < 0 then
						v:Destroy()
						
					end
					
				end
			end
		end
		
	end
	
end)

The Effects Script that Handles Tweening and Effects:

local model = Instance.new("Model",workspace)
workspace.ChildAdded:Connect(function(child)
	if child.Name == "ZaWarudo" then
			local ball = game.ReplicatedStorage.SpecialEffects.ZaBall:Clone()
			ball.Parent = model
			ball.Position = child.Value
			game:GetService("TweenService"):Create(ball,TweenInfo.new(5),{Size = Vector3.new(200,200,200),Transparency = 0.7}):Play()
			game.Debris:AddItem(ball,4)
			wait(1)
			game:GetService("TweenService"):Create(ball,TweenInfo.new(5),{Size = Vector3.new(1,1,1),Transparency = 1}):Play()
	end
	if child.Name == "DioKnifeHit" then
		repeat wait() until not game.Lighting:FindFirstChild("TSOTP")
		for i = 1,5 do
			local ball = game.ReplicatedStorage.Oval:Clone()
			ball.Position = child.Value
			ball.Parent = model
			ball.Material = "Neon"
			ball.BrickColor = BrickColor.new("Really red")
			local rng = math.random(4,9)
			ball.Orientation = Vector3.new(math.random(-360,360),math.random(-360,360),math.random(-360,360))
			game:GetService("TweenService"):Create(ball,TweenInfo.new(0.8),{Size = Vector3.new(8.92, 0.75, 0.48),Transparency = 1}):Play()
			game.Debris:AddItem(ball,1)
		end
	end
	if child.Name == "StrongPunch" then
		repeat wait() until not game.Lighting:FindFirstChild("TSOTP")
		for i = 1,5 do
			local ball = game.ReplicatedStorage.Oval:Clone()
			ball.Position = child.Value
			ball.Parent = model
			local rng = math.random(4,9)
			ball.Orientation = Vector3.new(math.random(-360,360),math.random(-360,360),math.random(-360,360))
			game:GetService("TweenService"):Create(ball,TweenInfo.new(0.8),{Size = Vector3.new(13,13,5),Transparency = 1}):Play()
			game.Debris:AddItem(ball,1)
		end
	end
	if child.Name == "NormalPunch" then
		repeat wait() until not game.Lighting:FindFirstChild("TSOTP")
		local ball = game.ReplicatedStorage.Oval:Clone()
		ball.Position = child.Value
		ball.Parent = model
		local rng = math.random(4,9)
		ball.Orientation = Vector3.new(math.random(-360,360),math.random(-360,360),math.random(-360,360))
		game:GetService("TweenService"):Create(ball,TweenInfo.new(0.8),{Size = Vector3.new(10,1,10),Transparency = 1}):Play()
		game.Debris:AddItem(ball,1)
	end
	if child.Name == "AoDSteal" then
		wait()
		local AoDSTarget = child.Value
		local AoDSOwner = child.Owner.Value
		for i = 1,5 do
			local ball = game.ReplicatedStorage.AoDLifeStealBall:Clone()
			ball.Position = AoDSTarget.PrimaryPart.Position
			ball.Parent = model
			game.Debris:AddItem(ball,3)
			spawn(function()
				game:GetService("TweenService"):Create(ball,TweenInfo.new(1),{Position = ball.Position + Vector3.new(math.random(-10,10),math.random(-10,10),math.random(-10,10)),Size = ball.Size + Vector3.new(math.random(0.5,1.5),math.random(0.5,1.5),math.random(0.5,1.5))}):Play()
				wait(1)
				game:GetService("TweenService"):Create(ball,TweenInfo.new(1),{Position = AoDSOwner.PrimaryPart.Position,Transparency = 1}):Play()
			end)
			
		end
	end
end)

(i tried using tables for the heartbeat script, but everytime i insert a descendants into the table the game Freezes for a few seconds, Which is bad, so i decided to use Pairs instead)

Game Link (if you want to check it out yourself)

High ping means you have a high latency to the game server. Try restarting your router and reconnect to your device to see if your issue can be resolve.

1 Like

so, it’s my internet fault? not my programming?

I don’t think it because of your programming. Cause the coding won’t affect your ping. Only your connection will.

Glad to hear that, but when i play other games such as Dota 2 i dont get a ping that high, so i think it’s probably because my place is far away from roblox servers

Yes. That could be it. Cause when I play CSGO I normally connect to Singapore server where it close to where I live. And if I play Arsenal my ping will be high cause the server might be from America or others country far away from where I live.

Yeah, I’m really not surprised your game isn’t performant. Look at your code again. You’re iterating over every descendant in the workspace, every frame. That is a colossal recipe for disaster, as is stuffing everything inside one script.

One script doesn’t necessarily equate to less lag, it just makes your code less readable and trips you up until maintenance of your game becomes difficult. I can’t quite tell what you’re doing because I don’t want to have to inspect a large code chunk across each line but you have some serious refactoring to do. Your code is majorly inefficient and that’s leading to latency problems.

Contrary to what’s been offered, yes your internet could be a problem but your code moreso will often cause the problem. In your case, it’s more your code than your internet. After all, you said playing other games is fine ping-wise.

4 Likes

I mean it could be both but I don’t know cause am not a good coder to be honest.

K, thanks!, so i should use a table and store it? and looping over the table,
or what?

Shouldn’t assert things you aren’t sure about then. In this scenario, the code is highly at fault due to the inefficient practices it employs. The code needs to be reviewed first before any connection is taken into account.

@eyrtuiop232 No, don’t even loop through the descendants of the workspace at all. What is your use case for doing so? Again, I’m not exactly willing to read your entire codebase to pick out issues for you, but I can tell with a quick glance that a lot here needs to be refactored.

Ok… so i tried to make a EMPTY BASEPLATE to try the ping, guess what?
i got 343 ping, lol.


so i guess it was my network after all, but nvm, that GetDescendants() method also very lag so i’ll just use weld