I put the code on Pastebin because it looks much more organized. All the explaining is done there. Basically, when a player presses 'k', I want an AI to spawn that reacts to them. This works in Play Solo, but online I get an error 'ai is a nil value'
You passed the client a reference to the object, but since the object is in ServerStorage, it won't be replicated to the client. Instead of keeping the NPC models in ServerStorage, put them in ReplicatedStorage. Objects in ReplicatedStorage can be accessed by both the server and client.
Ideally, you should have the server script do all the work of adding the AI to the Workspace and calling MakeJoints and creating the welds.
I don't know why this isn't working for you, but if you want to clone something to a LocalScript, why not just use ReplicatedStorage?
If you're trying to use Filtering, you'll alternatively have to offload all of the actually action-y code there to the server and connect a RemoteEvent to the clicking.
In play solo the character loads before the scripts do vs online/start server the scripts load before the character does so testing in play solo is just to make sure your script is set up right you might have to make some variables to allow the script to wait for the character to load