PartCache, for all your quick part-creation needs

: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

It works, thanks! However, I want them to fall when they spawn there. When they touch something they go back to the cache. How can I do this?

1 Like

Sounds like something that would depend on how your code is all setup, but I think use of the Touched event and Anchored property will help you with that.

1 Like

When you put a trail on the part you can see it being sent down and returned. How would you fix this?

1 Like

I had the same issue with the intended use with fastcast. My solution was to disable the trail when the bullets are put away and reenable them when they spawn back in.

Edit: Here is how it goes which uses the fastcasthandler approach. I had to coroutine a yield to guarantee the bullet gets moved into position then the trail activates but turns out it’s not that necessary just there if it happens.

Fastcast fire function which enables the trail if it finds one
		local fastcastHandler = {
			fastcast = castComponent,
			velocity = bulletVelocity or 1000,
			ratePerMinute = ratePerMinuteFire or rpm, --second per bullet
		}
		function fastcastHandler:Fire(origin, direction)
			local activeCast = self.fastcast:Fire(origin, direction, self.velocity, fastCastBehavior)
			local bullet = activeCast.RayInfo.CosmeticBulletObject
			local trail = bullet:FindFirstChildWhichIsA("Trail")
			if trail then
				trail.Enabled = false
				--coroutine.wrap(function()
					--Prevents the trail glitch from occuring
					--RunService.RenderStepped:Wait()
					trail.Enabled = true
				--end)()
			end
Clean up function disabling the trail using cast terminating like a good boy
		local function cleanUpBullet(activeCast)
			local bullet = activeCast.RayInfo.CosmeticBulletObject
			--Debris:AddItem(bullet,1)--normal instance.new clone
			local trail = bullet:FindFirstChildWhichIsA("Trail")
			if trail then
				trail.Enabled = false
			end
			projectileCache:ReturnPart(bullet)
		end

		castComponent.CastTerminating:Connect(cleanUpBullet)

It can be more optimized using bullet.Trail instead of FindFirstChild but I’m lazy :warning: so thats to avoid the fact that not all my bullets have a .Trail so just be aware of that.

10 Likes

Do I need to remove any connections and remove any parented instance in the part before using returnpart() or does the module revert the part automatically?

3 Likes