how can i make a entity like a spark spawn at the end of the raycast
Do you mean a particle effect or something?
yes