Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

My game is smaller than Jailbreak but laggier than Jailbreak?

Asked by 6 years ago
Edited 6 years ago

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

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) :) TheeDeathCaster 2368 — 6y

1 answer

Log in to vote
0
Answered by
mattscy 3725 Moderation Voter Community Moderator
6 years ago

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.

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? Konethorix 197 — 6y
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. mattscy 3725 — 6y
Ad

Answer this question