Raycast Filter Problem

The script is supposed to only explode when touching anything other than the player or ball. Although I set the exclude filter instances to the player.Characther it still explodes when touching the player.



local rep = game:GetService("ReplicatedStorage")

local ball = rep.Ball
local gravity = -100 -- negative numbers


local fastcast = require(rep.Dependencies.FastCastRedux)

local caster = fastcast.new()
local behavior = fastcast.newBehavior()





local remoteEvent = game.ReplicatedStorage.Throw
toolball = nil
player = script.Parent.Parent



remoteEvent.OnServerEvent:Connect(function(plr, mousePos, plrStrength)
 
	toolball = plr.Character.Dodgeball
	
	print(plr)
	print(mousePos)

	player = plr.Character
	local speed = plrStrength
	local pos = toolball.Handle.CFrame * CFrame.new(0,0,-50)
	local direction = (mousePos - toolball.Handle.Position).Unit
	
	caster:Fire(toolball.Handle.Attachment.WorldPosition,direction, speed, behavior)		
return toolball
end)

local params = RaycastParams.new()
params.FilterType = Enum.RaycastFilterType.Exclude
params.FilterDescendantsInstances = {toolball, player}


behavior.RaycastParams = params
behavior.Acceleration = Vector3.new(0, gravity, 0)
behavior.AutoIgnoreContainer = true
behavior.CosmeticBulletTemplate = ball
behavior.CosmeticBulletContainer = workspace.AvailableDodgeballs

caster.LengthChanged:Connect(function(ActiveCast, lastPoint, rayDir, displacement, segmentVelocity,  cosmeticBulletObject)
	
	local newPos = lastPoint + (rayDir * displacement)
	cosmeticBulletObject.Position = newPos
	
end)

caster.RayHit:Connect(function(ActiveCast, RaycastResult,  segmentVelocity,  cosmeticBulletObject)


	local  explosion = game.ReplicatedStorage.Explosion:Clone()
	explosion.Size = Vector3.new(20, 20, 20)
	explosion.Position = RaycastResult.Position
	explosion.Parent = workspace

	game:GetService("Debris"):AddItem(explosion, 0.2)
	cosmeticBulletObject.Parent = game.ReplicatedStorage
	end)


I probably have something wrong in the logic the problem is in params.FilterDescendantsInstances = {toolball, player}

1 Like

player seems to be a player Instance instead of the character. Set it to player.Character.

I did that in the OnServerEvent

I did that in the OnServerEvent (I accidently posted to topic)

The update does not carry over. You have to redo the params definition. Basically you have to set the FilterDescendantsInstances again when you change the player variable.

2 Likes

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