This probably won’t solve your problem, but I noticed that in your code you parent the beam within the Instance.new() call.
Awhile ago it was discovered that this can lead to some serious efficiency problems and it is recommended that you parent objects after setting all of their properties, like this:
local beam = Instance.new('Part')
-- Set all of the properties like BrickColor, Anchored, etc.
beam.Parent = game.Workspace
I, too, tested your script, only without Scriptily’s enhancements (just to see if those were fixing the problem) and I, too, found that your script works fine. I tested it in full client and server test mode instead of play solo as well.
Parts created in a LocalScript are seen only on the creator’s client, they don’t replicate to the server. If this is what you mean by not working online, the solutions are: Make the part on the server (will not feel responsive), or make the part on the creator’s client and also on the server, and then destroy the local part (or the new one) when the server one replicates to the creator’s client so they don’t see two copies.
In this special case, it probably does not make a huge difference because it’s presumably one part, non-collidable, for cosmetic display only. But, if you do something like this with a part that needs any physics simulation or collision detection to be consistent for all players or validated server-side, it would need to be done on the server.
I’ve done a lot of testing and basically removed every line one by one and replacing it with the original code, and this line is the line that ‘breaks’ it. If I change this line with the original line of code, it works to an extent (the ray just shoots down, instead of at the mouse)