Client side lag when invoking server [SOLVED!]

Hey devs,
I’m not sure what to name this post because I can’t tell very well what’s going on.
I made a very simple DVD Screensaver, and everything works fine when I play it in the editor, but when I’m playing from the Roblox client, whenever the logo hits a side of the screen, it stops for a bit before moving again.
Here’s video demonstrations:

In Editor:

In Client:

This code executes when the logo hits a corner:

-- Bottom Right Boundaries
	if DVD.Position.X.Scale >= 0.891 then
		xdirection = xdirection * -1
		SideHit()
	end
	if DVD.Position.Y.Scale >= 0.855 then
		ydirection = ydirection * -1
		SideHit()
	end
	
	-- Top Left Boundaries
	if DVD.Position.X.Scale <= 0 then
		xdirection = xdirection * -1
		SideHit()
	end
	if DVD.Position.Y.Scale <= 0 then
		ydirection = ydirection * -1
		SideHit()
	end

This is the SideHit() function it’s linking (and the color function it links as well):

local function SideHit()
	Side_Touched_Times.Value += 1
	ThisSession_SideHits += 1
	SwitchColor()
	SideTouched:InvokeServer()
end

local function SwitchColor()

	local Colors = {
		Color3.new(1, 0.121569, 0.0431373),
		Color3.new(0.0823529, 0.0823529, 1),
		Color3.new(0.552941, 1, 0.254902),
		Color3.new(0.439216, 0.180392, 1),
		Color3.new(1, 1, 1),
		[...]
	}

	local Color = Colors[math.random(1, #Colors)]
	DVD.ImageColor3 = Color
end

My only theory is that maybe the client waits for a server response or holds for a little bit when invoking the server?
Sorry for the low quality post, and thanks for any and all help in advance.

Edit: Uploaded videos instead of using streamable

yes it’s most likely invoke server yielding for a bit

2 Likes

Instead of invoking to the server, I think you should handle this all on client. When you are in Studio, the ping between server and client is little to none as both are being run on your computer. On client, it has some ping because Roblox handles the servers and your computer handles on client.

1 Like

I store how many sides the logo hits the sides on the server so when the player disconnects the server stores the variable on the player’s datastore.
I can’t think of any way to do that without calling the server every hit.
Is there a way?
Additionally, maybe there’s a way to avoid or ‘bypass’ the yield?

There is no way to bypass this yield. What you can do is store all hits on client, and when client is about to leave (ie. game:GetService(“Players”).PlayerRemoving, or instead handling this with a “save” button so no need for PlayerRemoving), the client sends that data to server through RemoteEvent (or RemoteFunction if you decide to go with save button), then Server attempts to save it to the DataStore.

1 Like

can’t you just use a remote event? it doesn’t cause a yield and you don’t really need a response either

2 Likes

That’s it! I completely overlooked that. I didn’t need a Remote Function.
That did the trick, thanks for the help!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.