Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

My game is smaller than Jailbreak but laggier than Jailbreak?

Is it because of the huge amount of scripts in hundreds of parts, or is it because I didn't use FilteringEnabled?

To be more specific, my game currently has 502 coins (just normal parts) and all of them have scripts inside. Seems like a very huge amount right?

I know, the description is short but all I need is some advice on how to reduce lag and make my game playable to everyone

1 comment

0

A good way is to use efficient code as much as possible, and cut down on scripts. (At least that's what I've been told, I think) :)

1 answer

✓ Accepted answer

Instead of having a separate script in every coin, you can just use one script and iterate through all the coins.

While you might do something like this in every coin script that you have:

script.Parent.Touched:Connect(function()
	--give coin here
end)

You are able to delete all the scripts in every coin and use just one script (possibly in ServerScriptService), and if you have all coin parts inside a folder/model called Coins in workspace, do something like this:

for _,coin in pairs(workspace.Coins:GetChildren()) do
	if coin:IsA("BasePart") then
		coin.Touched:Connect(function()
			--give coin here
		end)
	end
end

Also, if you have a large number of small parts that do not require collisions to be calculated on that small of a scale, you can try anchoring them all and setting all their CanCollide to false, and then just use a single invisible part with CanCollide true to act as a boundary.

You can also look here for more reading on improving the perfromance of your game.

2 comments

0

Is it 100% safe to handle hunreds and even thousands of parts using just one script?. And if I want to loop something, do I have to use coroutine, spawn() or RunService?

0

You shouldn't need to use coroutines or any of that as long as you don't add waits or any other form of yielding, and it should always work no matter how many parts there are.

This discussion is preserved as it was. New answers, comments, and votes are closed.