Hey so i tried your script and this is the error i get, also this is my entire script (minus the local function that activates a remote event), i also dont understand what you mean by castComponent and what that Debris is.
Script:
local Tool = script.Parent
local fireEvent = Tool:WaitForChild("FireEvent")
local FastCast = require(Tool.FastCastRedux)
local partCache = require(Tool.PartCache)
local GunData = script.Parent.GunData
local AmmoAmount = GunData:GetAttribute("AmountOfAmmo")
local GunDamage = GunData:GetAttribute("Damage")
local GunType = GunData:GetAttribute("GunType")
local BulletFolder = game.Workspace.BulletFolder
local Bullet = BulletFolder.Bullet
local caster = FastCast.new()
local castPerams = RaycastParams.new()
local CastBehavior = FastCast.newBehavior()
local bulletCache = partCache.new(Bullet, 100, BulletFolder)
CastBehavior.RaycastParams = castPerams
CastBehavior.Acceleration = Vector3.new(0, -workspace.Gravity, 0)
CastBehavior.AutoIgnoreContainer = false
CastBehavior.CosmeticBulletContainer = BulletFolder
CastBehavior.CosmeticBulletProvider = bulletCache
castPerams.FilterType = Enum.RaycastFilterType.Blacklist
castPerams.IgnoreWater = true
--------------------------------------------------------------------
local function onEquiped()
castPerams.FilterDescendantsInstances = {Tool.Parent, BulletFolder}
end
--------------------------------------------------------------------
local function onLengthChange (cast, lastPoint, direction, length, velocity, bullet2)
if bullet2 then
local BulletLength = bullet2.Size.Z/2
local offset = CFrame.new(0, 0, - (length - BulletLength))
bullet2.CFrame = CFrame.lookAt(lastPoint, lastPoint + direction):ToWorldSpace(offset)
end
end
--------------------------------------------------------------------
local function OnRayHit(cast, result, velocity, bullet2)
local hit = result.Instance
local character = hit:FindFirstAncestorWhichIsA("Model")
if character and character:FindFirstChild("Humanoid") then
character.Humanoid:TakeDamage(GunDamage)
end
delay(2, function()
bulletCache:ReturnPart(bullet2)
end)
end
--------------------------------------------------------------------
local function Fire(player, mousePosition)
local origin = Tool.Handle.FirePoint.WorldPosition
local direction = (mousePosition - origin).Unit
caster:Fire(origin, direction, 1000, CastBehavior)
end
--------------------------------------------------------------------
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
bulletCache:ReturnPart(bullet)
end
--------------------------------------------------------------------
fireEvent.OnServerEvent:Connect(Fire)
Tool.Equipped:Connect(onEquiped)
caster.LengthChanged:Connect(onLengthChange)
caster.RayHit:Connect(OnRayHit)
caster.CastTerminating:Connect(cleanUpBullet)
error:
