My game runs fine in Roblox Studio, but has extreme network lag when running it in the Roblox client

  1. What do you want to achieve? I want to make a movement system where I get an extra double jump when I pick up a green arrow power up, which is spinning in place.

  2. What is the issue? My code works fine, but when running the game my power up has extreme network lag, making it unusable.

Here’s what it looks like when running the game from Roblox (too slow to react, spinning animation is laggy:

And here’s what it looks like in Roblox Studio (intended):

  1. What solutions have you tried so far? I haven’t been able to find a solution to try, but I did find a few discussions out there that mention that too many events being passed from the server to the client may be an issue. I do have a RemoteEvent tied to when the player touches the hitbox of the powerup, but it should only be firing when something other than the arrow model is touching it (I set the collision group of the arrow model to 1, while leaving everything else at 0)

Here’s the code in every part of the game that interacts with this powerup.

The invisible hitbox of the power up:

wait(3)
local hitbox = script.Parent
local boostModel = hitbox.Parent
local arrow = boostModel.Arrow
local arrowColor = arrow.Color
local arrowTrans = arrow.Transparency

local rs = game:GetService("ReplicatedStorage")
local players = game:GetService("Players")

local BoostServerEvent = rs:WaitForChild("TouchedJumpBoost")

local isEnabled = true

local function PowerUpCooldown()
	isEnabled = false
	print("power up disabled")
	arrow.Color = Color3.new(0.584314, 0.584314, 0.584314)
	arrow.Transparency = 0.7
	arrow.ParticleEmitter.Enabled = false

	wait(5)

	isEnabled = true
	print("power up enabled")
	arrow.Color = arrowColor
	arrow.Transparency = arrowTrans
	arrow.ParticleEmitter.Enabled = true
end

hitbox.Touched:Connect(function(hit)
	if hit.Parent.Humanoid and isEnabled == true then
		local player = players:GetPlayerFromCharacter(hit.Parent)
		BoostServerEvent:FireClient(player)
		
		PowerUpCooldown()
	end
end)

The part of the movement script of the player which handles double jumping (It is a LocalScript in StarterPlayer):

local function onPowerUp()
	hasJumped = false
	canJumpAgain = true
end

BoostServerEvent.OnClientEvent:Connect(onPowerUp)

Lastly, the script inside the Arrow model that makes it rotate, just in case that has something to do with it

local p = script.Parent

--Rotate
local cf = CFrame.Angles(0,0.03,0)

while true do
	wait(0.001)
	p.CFrame = p.CFrame * cf
end
--

I would really love some ideas here. My internet is pretty good so I don’t expect there to be issues in that regard (nor do I think I would have the same problem if I did have bad internet). Has anyone else experienced this issue, or know how to fix it? Thanks!

1 Like

When you set the CollisionGroup of the arrow did you just type 1 into that Property, or did you click on the CollisionGroup tool in Studio and create the group, then add those Parts to the group and check which other groups it’s not contacting?
Also wait(.001) doesn’t actually work since the smallest time a wait can occur is every frame, so 1/60th of a second if you have no lag.

Simply changing wait(.001) to wait() fixed my issue lmao. I knew wait() would just do it every frame but thought wait(.001) would work just as well. Thanks!

A bit unrelated, but you should be using task.wait(). its the new wait() that shoulda always be used over it. wait() only waits a 1/30th of a second, which wouldn’t be every frame. task.wait() can actually wait lower than 1/60th of a second in some cases, and also has higher accuracy and performance than wait().

2 Likes