This won't work

the script prints true all time all

And FilterType is set to Exclude? That’s incredibly odd behaviour.

This could be a bug, but could you send a file so I can just check if your setup is right? It’s much more likely to be a logic error in your code.

yes

this is my whole projectile system script ( module ) in replicatedStorage



local Container = Instance.new("Folder")
Container.Name = "ProjectileContainer"
Container.Parent = workspace

local function Position(Origin, Initial, g, Time)
	return Origin + Initial * Time + g * Time * Time / 2
end

task.spawn(function()
	while task.wait(1/60) do
		pcall(function()
			for _,v in Container:GetChildren() do
				if v:IsA("BasePart") then
					local function RunPos(e)
						if not e then
							e = 0
						end
						return Position(v.Origin.Value, v.VVelocity.Value, v.Gravity.Value, v.Time.Value+e)
					end

					local cal = CFrame.lookAt(v.Position,RunPos(1/60))

					local params = RaycastParams.new()
					params.FilterType = Enum.RaycastFilterType.Exclude
					params.FilterDescendantsInstances = {v.Part.Value, v.Filter.Value:GetDescendants()}
					
					local new = {}
					local prevH = nil
					local currentwp = v.Position
					local currentdi = RunPos(1/60)-RunPos()
					
					local function Cast()
						local cast = workspace:Raycast(currentwp, currentdi,params)	
						if cast then
							if v.IgnoreAnchoredParts.Value == true and cast.Instance.Anchored then
								return
							end
							if v.IgnoreUnAnchoredParts.Value == true and not cast.Instance.Anchored then
								return
							end

						--[[local Indicator = Instance.new("BoolValue")
						Indicator.Name = "HitByProjectile"
						Indicator.Value = true
						Indicator.Parent = cast.Instance]]

							--
							local Hit = Instance.new("ObjectValue")
							Hit.Value = cast.Instance
							Hit.Name = "Hit"
							Hit.Parent = v
							local Position = Instance.new("Vector3Value")
							Position.Value = cast.Position
							Position.Name = "Position"
							Position.Parent = Hit
							local Normal = Instance.new("Vector3Value")
							Normal.Value = cast.Normal
							Normal.Name = "Normal"
							Normal.Parent = Hit
							--
							
							--print(cast.Instance==prevH)
							prevH = cast.Instance
							currentwp+=v.CFrame.LookVector
							params:AddToFilter(cast.Instance)
							local p = game.ReplicatedStorage.DebugPart:Clone()
							p.Position = cast.Position
							p.Parent = workspace
							print(cast.Instance)
							print(table.find(params.FilterDescendantsInstances, cast.Instance) ~= nil)
							
						end
					end
					
					local x = 0
					repeat
						Cast()
						x+=1
					until x>=v.Penetration.Value
					
					v.CFrame = CFrame.new(RunPos())*cal.Rotation
					v.Time.Value+=1/60

					
					
					if (v.Origin.Value-v.Position).Magnitude>=v.Distance.Value then
						v:Destroy()
					end
					if v.Position.Y<=workspace.FallenPartsDestroyHeight then
						v:Destroy()
					end

				end
			end
		end)
	end
end)

local module = {}

function module:Emit(Part:BasePart,Config)
	assert(Part,"The part parameter is used to defy where the projectile will be at, and if no direction is passed it will be set to the parts lookvector")
	
	local Projectile = Config and Config.Projectile or Instance.new("Part")
	local Force = Config and  Config.Force or 10
	local Spread = Config and  Config.Spread or 10
	local Gravity = Config and  Config.Gravity or workspace.Gravity
	local Filter = Config and  Config.Filter or Part
	local IgnoreAnchoredParts = Config and  Config.IgnoreAnchoredParts or false
	local IgnoreUnAnchoredParts = Config and  Config.IgnoreUnAnchoredParts or false
	local Distance = Config and  Config.Distance or 10000
	local Direction = Config and  Config.Direction or nil
	local LookAt = Config and  Config.Lookat or nil
	local Penetration = Config and  Config.Penetration or 1

	Force*=1
	
	local function AddData(Name,Value,Type)
		if not Type then
			Type = "NumberValue"
		end
		local c = Instance.new(Type)
		c.Value = Value
		c.Name = Name
		c.Parent = Projectile
	end
	
	
	AddData("Time",1/60)
	AddData("Spread",Spread)
	AddData("Distance",Distance)

	AddData("Part",Part,"ObjectValue")
	AddData("Filter",Filter,"ObjectValue")
	
	AddData("IgnoreAnchoredParts",IgnoreAnchoredParts,"BoolValue")
	AddData("IgnoreUnAnchoredParts",IgnoreUnAnchoredParts,"BoolValue")

	local o = Vector3.new(Random.new():NextNumber(-Spread,Spread)  , Random.new():NextNumber(-Spread,Spread) , Random.new():NextNumber(-Spread,Spread))
	Projectile.CFrame = Part.CFrame
	if Direction then
		Projectile.CFrame = CFrame.lookAt(Projectile.Position,Projectile.Position+Direction)
	end
	if LookAt then
		Projectile.CFrame = CFrame.lookAt(Projectile.Position,LookAt)
	end
	Projectile.Position+=(Projectile.CFrame.LookVector*Projectile.Size.Z/2)
	Projectile.Orientation+=o
	
	AddData("VVelocity",Projectile.CFrame.LookVector*Force,"Vector3Value")
	AddData("Origin",Part.Position,"Vector3Value")
	AddData("Gravity",Vector3.new(0,-Gravity,0),"Vector3Value")
	Projectile.Parent = Container
	
end

return module

the gun client shoots the projectile and the red highlights come from this system itself which meaning it’s not the guns fault

When getting FilterDescendantsInstances, you’re getting a cloned version of it.

local p = RaycastParams.new()
print(p.FilterDescendantsInstances == p.FilterDescendantsInstances) --> false

Adding to the clone won’t affect the original list! Use params:AddToFilter() like others said.

1 Like

This should probably be:
params.FilterDescendantsInstances = { v.Part.Value, v.Filter.Value }
…assuming v.Filter is an ObjectValue Instance pointing to the root-most Instance you want excluded.

If you have some other array of instances you want to append, you can’t just put an array into the array, you’d need to use unpack() to get a tuple from the array or loop through the array and add the elements one at a time.

FilterDescendantInstances takes an array of instances and excludes all descendants of the instances you put in it. You don’t need to add all the descendants yourself, just the root-level instances.

1 Like

ok I’ve done this and it works well and is more performant

ok I’ve done it now my problem is it is still colloding

You should just step through the code in the debugger. There is probably something wrong in the actual logic. Like I see that you have code which returns early from Cast() if your raycast hits an anchored or unanchored part that you’re trying to ignore. But it returns without adding the ignored part to the filtered instances, so it will just keep hitting that same part. Put breakpoints on both of those early returns. This is probably a bug you have to fix even if it’s not causing the current problem.

Specifically, I’d expect this:

if v.IgnoreAnchoredParts.Value == true and cast.Instance.Anchored then
    return
end
if v.IgnoreUnAnchoredParts.Value == true and not cast.Instance.Anchored then
    return
end

to be:

if v.IgnoreAnchoredParts.Value == true and cast.Instance.Anchored then
    params:AddToFilter( cast.Instance )
    return
end
if v.IgnoreUnAnchoredParts.Value == true and not cast.Instance.Anchored then
    params:AddToFilter( cast.Instance )
    return
end
1 Like