Functions works but returns nil? [SOLVED]

I’m making function to check if Fast-Cast can pierce a part, the for a gun.

the canRayPeirce function somehow runs twice meaning

castBehavior.CanPierceFunction = canRayPierce

is running twice?

Things I’ve Tried to Solve The Problem

  • Debugging my code to check if its my code thats the problem or Fast-Cast.

  • Adding a debounce value

This is My Code

function canRayPierce(activeCast, result, velocity, bullet)
	local canPierce = false
	local depthOfWall = getOfPartDepth(bullet.Position+(-velocity.Unit) , velocity.Unit, result.Instance)
	
	print('sending? : '..tostring(depthOfWall))
	if depthOfWall and depthOfWall <= configs:GetAttribute('PierceThickness')  then
		canPierce = true
	else
		print('failed? : '..tostring(depthOfWall))
	end
	
	return canPierce
end

castBehavior.CanPierceFunction = canRayPierce

This is my output :

… | sending? : 2.6673853397369385 - Server
… | sending? : nil - Server
… | failed? : nil - Server

What should i do? and is it a problem with Studio, Fast-Cast or my Code?

If the line you mentioned is being executed twice, we can add a check to see if it has been run, and if not, then activate it. Try adding this to the line you mentioned and see if it works:

if not castBehavior.CanPierceFunction then
    castBehavior.CanPierceFunction = canRayPierce
end

Haha… there no problem with the code. I forgot that fast-cast stops to check if it can pierce and then i sends another ray to continue moving in its path…

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