Help optimizing this Dialog Script for slower internet speeds

Hello! I’m developing a Singleplayer game and I have come across some issues regarding my dialog script function.
It works well for MOST connections, but I’ve seen players and videos of people complaining that the dialog loads weirdly in chunks or just skips’

Is there any way to optimize this? This is on a ServerScript.

function setDialogText(Text, gender) -- set sound that will play in the dialog
	
	local dialogsfx = workspace.DialogSound
	local defaultwaittime = 0.05
	
	-- variables --
	--gender
	
	local dialogData = {
		["mom"] = {
			dialogsfx = workspace.Sounds.Dialog.FemaleDialogSound,
			waittime = 0.07
		},
		["koolaid"] = {
			dialogsfx = workspace.Sounds.Dialog.KoolDialogSound,
			waittime = 0.055
		},
		["bing"] = {
			dialogsfx = workspace.Sounds.Dialog.BingCDialog,
			waittime = defaultwaittime
		},
		["dad"] = {
			dialogsfx = workspace.Sounds.Dialog.FatherDialog,
			waittime = 0.085
		},
		["manager"] = {
			dialogsfx = workspace.Sounds.Dialog.ManagerDialog,
			waittime = defaultwaittime
		},
		["baconman"] = {
			dialogsfx = workspace.Sounds.Dialog.BaconManDialogSound,
			waittime = 0.05
		},
		["baconwoman"] = {
			dialogsfx = workspace.Sounds.Dialog.BaconWomanDialog,
			waittime = 0.055
		},
		["cat"] = {
			dialogsfx = workspace.Sounds.Dialog.CatDialog,
			waittime = defaultwaittime
		},
		
		["carey"] = {dialogsfx = workspace.Sounds.Dialog.CareyDialog, waittime = 0.06}
	}

	if gender == nil then
		dialogsfx = workspace.DialogSound
		waittime = defaultwaittime
	else
		local genderData = dialogData[gender]
		if genderData then
			dialogsfx = genderData.dialogsfx
			waittime = genderData.waittime
		else
			dialogsfx = workspace.DialogSound
			waittime = defaultwaittime
		end
	end
	--------------------
	Frame.Changed:Connect(function()
		if Frame.Visible == true then
			MoneyGUI.Visible = false
		else
			MoneyGUI.Visible = true	
			inDialog = false
		end
	end)
	
	inDialog = true
	--Frame.Visible = true
	for i = 1, #Text do
		dialog.Text = string.sub(Text, 1, i)
		dialog.Rotation = 0
		dialog.TextColor3 = Color3.fromRGB(255,255,255)
		dialogsfx:Play()
		
		if string.sub(Text, i, i) == "," or string.sub(Text, i, i) == "." or string.sub(Text, i, i) == "!" or string.sub(Text, i, i) == "?" then
			task.wait(0.2)
		end
		
		task.wait(waittime)
	end
		
       -- Dont mind this part because it just makes a fram visible and invisible.
	Frame.Changed:Connect(function()
		if Frame.Visible == true then
			MoneyGUI.Visible = false
		else
			MoneyGUI.Visible = true
			inDialog = false
		end
	end)
end

Help would be VERY appreciated, thanks!

1 Like

Filtering enable helps alot in game optimazation

Wdym? Isn’t filtering enabled forced by default nowdays?

Did you mean content streaming (streaming enabled)?

I though the title said faster, my bad

Ping is the answer to your question.

Ping is the time it takes for a device to send data to the server, then the server sends data back to the device. For a player with a higher ping, your code will run slower.

Have you tried using this code in a local script instead? I don’t recommend using loops like this on the server.

2 Likes

Hes right, the only way i see this being more efficient on serverside is implementing run service to avoid memory leaks and making too many threads.

I did try doing something like that in another Place and the same issue happened.

How would you implement RunService into that? I apologise but I’m not too experiened with that.

where is that function being called? that might be the issue Im not seeing it anywhere

It is called a lot of times later down the script. All the script is about 2k lines of code since it handles most of the “story” aspect of my game.

Simply, you shouldn’t be using a script rather a local script.

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