Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

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

Asked by 10 years ago

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

0
What's the line number of the error? Merely 2122 — 10y
0
Line 28 at the pastebin link. The error is: ForeverDev 155 — 10y
0
Players.Player1.PlayerGui.LocalScript:18: attempt to index local 'ai' (a nil value) ForeverDev 155 — 10y
0
Line 23**** my bad. ForeverDev 155 — 10y
View all comments (2 more)
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. Merely 2122 — 10y
0
Yeah, it printed out nil. ForeverDev 155 — 10y

3 answers

Log in to vote
3
Answered by
Merely 2122 Moderation Voter Community Moderator
10 years ago

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.

0
Ah, it worked! Thanks. ForeverDev 155 — 10y
0
OP's using a Clone of the member from ServerStorage, which would be Parented to nil I thought? adark 5487 — 10y
Ad
Log in to vote
2
Answered by
adark 5487 Badge of Merit Moderation Voter Community Moderator
10 years ago

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
I had actually been using ReplicatedStorage earlier. I just switched to ServerStorage to see if it would somehow fix the problem. ForeverDev 155 — 10y
Log in to vote
1
Answered by 10 years ago

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

Answer this question