Fast cast didnt work properly

I want to make a gatling pea shoots 4 pea in a row and damage zombies.
However this is what happens:

Code (functions):

local pea = game.Lighting:WaitForChild("Pea")
local castmodule = require(game.ReplicatedStorage:WaitForChild("FastCastRedux"))
local caster = castmodule.new()
local origin = script.Parent.ShootPart.Position
local direction = script.Parent.ShootPart.CFrame.LookVector
local castparams = RaycastParams.new()
castparams.FilterType = Enum.RaycastFilterType.Whitelist
castparams.IgnoreWater = true
castparams.FilterDescendantsInstances = {game.Workspace.Zombies}
local castbehaviour = castmodule.newBehavior()
castbehaviour.RaycastParams = castparams
castbehaviour.AutoIgnoreContainer = false
castbehaviour.CosmeticBulletContainer = game.Workspace.ETC
castbehaviour.CosmeticBulletTemplate = pea

local function onlengthchanged(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)
	print("hit!")
	local debounce = true
	local hit = result.Instance
	local humanoid = hit.Parent:FindFirstChildOfClass("Humanoid")
	if humanoid then
		local zombi = humanoid.Parent:FindFirstChild("Zombies")
		if zombi and debounce == true then
			debounce = false
			local thingy = game.Lighting.Effect.Effect1:Clone()
			thingy.CFrame = bullet.CFrame
			thingy.Parent = game.Workspace
			game:GetService("Debris"):AddItem(bullet,0)
			humanoid:TakeDamage(10)
			local sound = game.Lighting.Hit:Clone()
			sound.Parent = game.Workspace.Sound
			sound:Destroy()
		end
		game:GetService("Debris"):AddItem(bullet,8)
end
end

Code (runner)

function ShootBean()
	caster:Fire(origin,direction,40, castbehaviour)
	caster.LengthChanged:Connect(onlengthchanged)
	caster.RayHit:Connect(Onrayhit())
	--[[
	local debounce = true
	--local bean = script.Parent.ShootPart:Clone()
--	bean.Name = "Bean"
	--local velocity = Instance.new("BodyVelocity",bean)
	--velocity.Velocity = script.Parent.Main.CFrame.LookVector * 40
--	bean.Anchored = false
--	bean.CanCollide = false
---	bean.Transparency = 0
--	bean.Parent = game.Workspace.ETC
	--[[
	local dafunction = bean.Touched:Connect(function(hit)
		local humanoid = hit.Parent:FindFirstChildOfClass("Humanoid")
		if humanoid then
			local zombi = humanoid.Parent:FindFirstChild("Zombies")
			if zombi and debounce == true then
				debounce = false
				local thingy = game.Lighting.Effect.Effect1:Clone()
				thingy.CFrame = bean.CFrame
				thingy.Parent = game.Workspace
				game:GetService("Debris"):AddItem(bean,0)
				humanoid:TakeDamage(10)
				local sound = game.Lighting.Hit:Clone()
				sound.Parent = game.Workspace.Sound
				sound:Destroy()
			end
		end
	end)
	if debounce == false then
		dafunction:Disconnect()
		game:GetService("Debris"):AddItem(bean,0)
	end
	game:GetService("Debris"):AddItem(bean,15)
	--]]
end

Since this is my first time using fast cast. I dont know how to fix!

Thanks :slight_smile:

1 Like

Dont mind the beam. It not about this case :smiley:

1 Like