This function fires a Ray and the PartCache Module handles the Bullet Trails, meaning a part that look like a bullet trail will be CFramed as the path of the casted Ray.
The problem is that when I add this:
BulletTemplate.Shape = "Cylinder"
The parts stop CFraming, even though there is no error. Without adding this everything works fine.
Script:
local AmmoFolder = workspace:WaitForChild("AmmoFolder")
local BulletTemplate = Instance.new("Part")
BulletTemplate.Anchored = true
BulletTemplate.CanCollide = false
BulletTemplate.Color = Color3.new(1, 0.835294, 0)
BulletTemplate.Transparency = 0.1
BulletTemplate.Shape = "Cylinder"--Adding this line makes the parts not CFrame, even though without it everything works fine
BulletTemplate.Material = Enum.Material.Neon
local BulletCache = ClientPartCach.new(BulletTemplate, 3, AmmoFolder)
local function ShootBullet(ViewRay, Muzzle)
local CachedBullet = ClientPartCach.GetPart(BulletCache)
local MuzzlePosition = Muzzle.Position
if Ammo > 0 and Reloading == false then
local ray = workspace:Raycast(MuzzlePosition, ViewRay.Direction * 300) --+ Vector3.new(math.random(-5, 5), math.random(-5, 5), math.random(-5, 5)))
if ray ~= nil then
local RayPosition = ray.Position
CachedBullet.Size = Vector3.new(0.15, 0.15, (MuzzlePosition - RayPosition).Magnitude)
CachedBullet.CFrame = CFrame.new(MuzzlePosition + (RayPosition - MuzzlePosition)/2, RayPosition)
else
print("Out of range")
CachedBullet.CFrame = CFrame.lookAt(MuzzlePosition + (ViewRay.Direction * 300)/2, MuzzlePosition + ViewRay.Direction * 300)
CachedBullet.Size = Vector3.new(0.15, 0.15, 300)
end
Ammo -= 1
AmmoGui.Text = Ammo
task.wait(0.01)
BulletCache:ReturnPart(CachedBullet)
elseif Ammo <= 0 and Reloading == false then
Reload()
end
end
Also, your .GetPart is wrong, read the documentation for an example.
Code:
local AmmoFolder = workspace:WaitForChild("AmmoFolder")
local BulletTemplate = Instance.new("Part")
BulletTemplate.Anchored = true
BulletTemplate.CanCollide = false
BulletTemplate.Color = Color3.new(1, 0.835294, 0)
BulletTemplate.Transparency = 0.1
BulletTemplate.Shape = Enum.PartType.Cylinder --Adding this line makes the parts not CFrame, even though without it everything works fine
BulletTemplate.Material = Enum.Material.Neon
local BulletCache = ClientPartCach.new(BulletTemplate, 3, AmmoFolder)
local function ShootBullet(ViewRay, Muzzle)
local MuzzlePosition = Muzzle.Position
if Ammo > 0 and Reloading == false then
local CachedBullet = BulletCache:GetPart()
local ray = workspace:Raycast(MuzzlePosition, ViewRay.Direction * 300) --+ Vector3.new(math.random(-5, 5), math.random(-5, 5), math.random(-5, 5)))
if ray ~= nil then
local RayPosition = ray.Position
CachedBullet.Size = Vector3.new((MuzzlePosition - RayPosition).Magnitude, 0.15, 0.15)
CachedBullet.CFrame = CFrame.lookAt(MuzzlePosition + (RayPosition - MuzzlePosition)/2, RayPosition) * CFrame.Angles(0, math.rad(90), 0)
else
print("Out of range")
CachedBullet.CFrame = CFrame.lookAt(MuzzlePosition + (ViewRay.Direction * 300)/2, MuzzlePosition + ViewRay.Direction * 300) * CFrame.Angles(0, math.rad(90), 0)
CachedBullet.Size = Vector3.new(300, 0.15, 0)
end
Ammo -= 1
AmmoGui.Text = Ammo
task.wait(0.01)
BulletCache:ReturnPart(CachedBullet)
elseif Ammo <= 0 and Reloading == false then
Reload()
end
end
As for PartCache, if I change the GetPart operator from : to a . it gives me an error and doesnt work. “Cannot statically invoke method ‘GetPart’ - It is an instance method. Call it on an instance of this class created via PartCache.new”
I just copied the code from a guy that helped me set this up on DevHub because I couldn’t set it up myself, and I didn’t find any tutorials for PartCache online.
local CachedBullet = ClientPartCach.GetPart(BulletCache)
to this:
local CachedBullet = BulletCache:GetPart()
It still doesn’t work, but no error this time. Did you change anything else in the script that I didn’t see? I don’t want to Ctrl C, Ctrl V the whole code since I have lots of annotations in the main script.
This did fix the problem, thank you! Could you explain why exactly? My code worked well if I didn’t change the part’s shape, it’s a bit strange for me.