PartCache, for all your quick part-creation needs

It depends on your implementation. In your specific case, I’d advise against using parts if your goal is to have single particles emit at random locations. A better choice might (I say might because I don’t actually know what you’re trying to do) be to parent an Attachment to terrain. CFrame the attachment, emit the particle, delay, repeat. You could have a single attachment + emitter and just randomly emit around your area. That, or better yet, just make a big part and use Roblox’s random placement (but I assume you’re avoiding that for a reason).

To answer your question, I’d advise having it all in one single function, wait included. That, or use spawn instead of coroutine.wrap as spawn ties into Roblox’s scheduler (same system as wait for the most part)

It could be done relatively easily, the issue is that there’s no real purpose for it unless you’re building close to the preset position, which would cause other far more severe problems for your game

5 Likes

Cool module, any chance you would add the Luau type annotations to it?

2 Likes

Oh yeah! I hadn’t actually realized it was released. I can do that ASAP.

Edit: Update is out. Of course, scripts may show a number of false warnings due to type checking beta. There is now a “README” script in the module that goes over what to expect.

3 Likes

I am looking through the module code but unable to figure out :exploding_head: where I change the default parent object for the cached parts.
Now they are all parented to the Workspace.
Is it possible to specify the parent object for each cache?

2 Likes

Look at the main post, at the bottom. There’s a ref sheet.

2 Likes

:GetPart(), not .GetPart()

As for moving the part as a bullet, I wrote a module for that too, and the module actually can tie into this one. See FastCast.

2 Likes

Do the parts in the cache need to be anchored? I doubt that their physics are simulated when they are so far away, but I want to make sure.

2 Likes

Yes, they need to be anchored when stored.

2 Likes

Epic, thanks for that response time.

1 Like

Could you post some a script for some of us noobs :c

1 Like

When moving cached parts to a position, should I use CFrame to position them or use the position property?

1 Like

Sorry to put this warning here but I can’t create a new topic in Studio Bugs.

This warning comes up when I open the script for PartCache, its something about Free types.
This is the first time I have tried to use PartCache and the warning came up.
It is in the PartCache module script.

image

3 Likes

Anything I can do about this?

18d4918f186babbeba7e6510f29f860c

1 Like

Please try to actually describe what’s wrong. What you’ve effectively done is sat down at a restaurant, and told the waiter “Yes, please give me some food.”

I’m going to need to know what the problem actually is if you want guidance on it. When is this happening?

4 Likes

Sorry for the late response, came here from a hyperlink.

Anyways for a solution I handled objects that aren’t necessary to the server, like bullet trails (that don’t need collision) on the client. Reduced the Network problem.

Essentially what was wrong is I was using part cache only on the server. I had to make my own for the client but it didn’t take too long thanks to you making your scripts easy to read, thank you.

2 Likes

Whats happening…

local RandomPosModule = require(script.RandomPositionModule)
local PartCacheModule = require(script.Parent.PartCache)

local Droplet = game.ReplicatedStorage.RainDroplet
local ModuleRain = PartCacheModule.new(Droplet, 50)

while wait() do
	
		for i = 1,(script.Parent.Amount.Value) do
		
		local DropletClone = PartCacheModule.GetPart(ModuleRain)
		
		DropletClone.Parent = workspace
		RandomPosModule.RandomPosition(script.Parent,DropletClone)
		
	end
end
1 Like

You need to return the part to the cache at some point using ReturnPart.

1 Like

Oh, let me give it a try.
Thank you.

1 Like
local RandomPosModule = require(script.RandomPositionModule)
local PartCacheModule = require(script.Parent.PartCache)

local Droplet = game.ReplicatedStorage.RainDroplet
local ModuleRain = PartCacheModule.new(Droplet, 50)

while wait() do

	for i = 1,(script.Parent.Amount.Value) do

		local DropletClone = PartCacheModule.GetPart(ModuleRain)

		DropletClone.Parent = workspace
		RandomPosModule.RandomPosition(script.Parent,DropletClone)
		
		ModuleRain:ReturnPart(DropletClone)
	end
end

so now theres no errors, but its not spawning. Its just staying un-used

1 Like

You’re instantly returning to the cache afterwards. You’ll probably want something like this.

local RandomPosModule = require(script.RandomPositionModule)
local PartCacheModule = require(script.Parent.PartCache)

local Droplet = game.ReplicatedStorage.RainDroplet
local ModuleRain = PartCacheModule.new(Droplet, 50)

while true do
	local parts = {}
	for i = 1,(script.Parent.Amount.Value) do

		local DropletClone = PartCacheModule.GetPart(ModuleRain)

		DropletClone.Parent = workspace
		RandomPosModule.RandomPosition(script.Parent,DropletClone)
		
		table.insert(parts, DropletClone)
	end

	wait()

	for _, part in ipairs(parts) do
		ModuleRain:ReturnPart(part)
	end
end
5 Likes