Need help with scripting aiming system for magic attacks

So I’m making a game. Most of the time, when I use magic, I just find the player’s mouse position and make the attack go there. However, this time, I’m making it so that other players can use magic barriers to block attacks. How can I make it so that the magic moves detonates early when hitting a barrier or a obstacle that wasn’t in the way before? Maybe constant raycasting or just going in a DIRECTION until it hits something?

Also, if it helps, the “barrier” is a part that wraps around the player if they activate it. It’s cancollide is set to false.

1 Like

Or you could wait until the collision and do a check to see if the player has the shield(?) enabled and if they don’t then do what you’re gonna do.

That way you don’t have to waste resources as much

This is just a suggestion though


The shield has a set durability. It absorbs the damage taken, but if the damage taken is greater than its durability, it just subtracts the amount of damage by its durability. The shield also has a model. So I want it to explode when it hits the model (Non collidable), not when it hits the player. (There is a sizable gap between player and shield). Any ways to detect non collidable objects?

Sorry for the late response. Try enabling CanQuery but not CanCollide

Well if you’re still raycasting of course which it seems like you are ig

1 Like

You could make the magic a projectile which is attracted towards a line force (mouse.Hit) and the projectile has a hitbox around it. When it hits the barrier/shield you could run the durability function. Also a cool way to break parts is to build them from smaller pieces and weld them all together the use :BreakJoints on the model to shatter it.