Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

I'm completely lost as to why this only works in Play Solo... Why is this happening?

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'

http://pastebin.com/2XJ4MvsQ

6 comments

0

What's the line number of the error?

0

Line 28 at the pastebin link. The error is:

0

Players.Player1.PlayerGui.LocalScript:18: attempt to index local 'ai' (a nil value)

0

Line 23**** my bad.

0

Before parenting ai to Workspace, add print(ai) to see if it's nil. It should have errored on line 24 if it was nil.

0

Yeah, it printed out nil.

3 answers

✓ Accepted answer

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.

2 comments

0

Ah, it worked! Thanks.

0

OP's using a Clone of the member from ServerStorage, which would be Parented to nil I thought?

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.

1 comment

1

I had actually been using ReplicatedStorage earlier. I just switched to ServerStorage to see if it would somehow fix the problem.

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

This discussion is preserved as it was. New answers, comments, and votes are closed.