FastCast Raycasting Problem

Hey there developers!

I was trying to follow a YT tutorial on using the FastCast and PartCache modules for Raycasting bullets when I came into a problem

The error is saying “Workspace.Semi-Auto Gun.PartCache:141: attempt to call missing method ‘GetFullName’ of table”

Here’s my script.

local tool = script.Parent
local fireEvent = tool.FireEvent
local FastCast = require(tool.FastCastRedux)
local PartCache = require(tool.PartCache)
local firePoint = tool.Handle.FirePoint
local speed = tool:GetAttribute("Speed")
local damage = tool:GetAttribute("Damage")

local bulletsFolder = Instance.new("Folder", workspace) or workspace:FindFirstChild("BulletFolder")
bulletsFolder.Name = "BulletFolder"

local bulletTemplate = Instance.new("Part")
bulletTemplate.Anchored = true
bulletTemplate.CanCollide = false
bulletTemplate.Shape = "Block"
bulletTemplate.Size = Vector3.new(0.2, 0.2, 1)
bulletTemplate.Material = Enum.Material.Neon
bulletTemplate.BrickColor = BrickColor.new("190")
	
--FastCast.VisualizeCasts = false

local caster = FastCast.new()

local castParams = RaycastParams.new()
castParams.FilterType = Enum.RaycastFilterType.Exclude
castParams.IgnoreWater = false

local bulletCache = PartCache.new(bulletTemplate, 300, bulletsFolder)

local castBehavior = FastCast.newBehavior()
castBehavior.RaycastParams = castParams
castBehavior.Acceleration = Vector3.new(0, -workspace.Gravity, 5)
castBehavior.AutoIgnoreContainer = false
castBehavior.CosmeticBulletContainer = bulletsFolder
castBehavior.CosmeticBulletProvider = bulletCache

local function onEquipped()
	castParams.FilterDescendantsInstances = {tool.Parent, bulletsFolder}
end

local function onLenghtChanged(cast, lastPoint, direction, length, velocity, bullet)
	if bullet then
		local bulletLength = bullet.Size.Z/2
		local offset = CFrame.new(0, 0, -(length - bulletLength))
		bullet.CFrame = CFrame.lookAt(lastPoint, lastPoint + direction):ToWorldSpace(offset)
	end
end

local function onRayHit(cast, result, velocity, bullet)
	local hit = result.Instance
	
	local character = hit:FindFirstAncestorWhichIsA("Model")
	if character and character:FindFirstChild("Humanoid") then
		character.Humanoid:TakeDamage(damage)
	end
end

local function fire(player, mousePosition)
	local origin = firePoint.WorldPosition
	local direction = (mousePosition - origin).Unit

	caster:Fire(origin,direction, speed, castBehavior)
end

delay(5, function()
	bulletCache:ReturnPart(bulletCache) -- i think this is where the error is happening
end)

fireEvent.OnServerEvent:Connect(fire)

tool.Equipped:Connect(onEquipped)

caster.LengthChanged:Connect(onLenghtChanged)
caster.RayHit:Connect(onRayHit)

The error isn’t being sent from this script its being sent from the PartCache Module

If anybody could help me out, thanks in advance!

-VeilStrife

local tool = script.Parent
local fireEvent = tool.FireEvent
local FastCast = require(tool.FastCastRedux)
local PartCache = require(tool.PartCache)
local firePoint = tool.Handle.FirePoint
local speed = tool:GetAttribute("Speed")
local damage = tool:GetAttribute("Damage")

local bulletsFolder = Instance.new("Folder", workspace) or workspace:FindFirstChild("BulletFolder")
bulletsFolder.Name = "BulletFolder"

local bulletTemplate = Instance.new("Part")
bulletTemplate.Anchored = true
bulletTemplate.CanCollide = false
bulletTemplate.Shape = "Block"
bulletTemplate.Size = Vector3.new(0.2, 0.2, 1)
bulletTemplate.Material = Enum.Material.Neon
bulletTemplate.BrickColor = BrickColor.new("190")
	
--FastCast.VisualizeCasts = false

local caster = FastCast.new()

local castParams = RaycastParams.new()
castParams.FilterType = Enum.RaycastFilterType.Exclude
castParams.IgnoreWater = false

local bulletCache = PartCache.new(bulletTemplate, 300, bulletsFolder)

local castBehavior = FastCast.newBehavior()
castBehavior.RaycastParams = castParams
castBehavior.Acceleration = Vector3.new(0, -workspace.Gravity, 5)
castBehavior.AutoIgnoreContainer = false
castBehavior.CosmeticBulletContainer = bulletsFolder
castBehavior.CosmeticBulletProvider = bulletCache

local function onEquipped()
	castParams.FilterDescendantsInstances = {tool.Parent, bulletsFolder}
end

local function onLenghtChanged(cast, lastPoint, direction, length, velocity, bullet)
	if bullet then
		local bulletLength = bullet.Size.Z/2
		local offset = CFrame.new(0, 0, -(length - bulletLength))
		bullet.CFrame = CFrame.lookAt(lastPoint, lastPoint + direction):ToWorldSpace(offset)
	end
end

local function onRayHit(cast, result, velocity, bullet)
	local hit = result.Instance
	
	local character = hit:FindFirstAncestorWhichIsA("Model")
	if character and character:FindFirstChild("Humanoid") then
		character.Humanoid:TakeDamage(damage)
	end

delay(5, function()
	bulletCache:ReturnPart(bullet) 
end)
end

local function fire(player, mousePosition)
	local origin = firePoint.WorldPosition
	local direction = (mousePosition - origin).Unit

	caster:Fire(origin,direction, speed, castBehavior)
end



fireEvent.OnServerEvent:Connect(fire)

tool.Equipped:Connect(onEquipped)

caster.LengthChanged:Connect(onLenghtChanged)
caster.RayHit:Connect(onRayHit)

Explanation:
bulletCache:ReturnPart(param) gets rid of the part given as parameter.
This exists because it should destroy the bullet after it hit something else it would result in a flying bullet just hanging there. Therefore you put this into the onRayHit() function since that’s the function connected to the event which fires once the ray hits something.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.