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

Location of this script returns nil?

Here Is (part of) a script that I am using for my game:

local sss = game:GetService("ServerScriptService")
--.........
sss:FindFirstChild("Game").Disabled = true
--.........
sss:FindFirstChild("Game").Disabled = false

It runs fine in studio, but in play mode this error pops up: Players.PyccknnXakep.PlayerGui.GameScript:69: attempt to index a nil value So I put in a short snippet of code inside of the Game script located in the serverscriptservice: print(script.Parent) It returns ServerScriptService, but the GameScript in the StarterGui won't disable it and says it doesn't exist. This might be a small syntax error, but any help would be greatly appreciated.

4 comments

0

could try :WaitForChild("Game")

0

Is "GameScript" a local script or a server-side script?

0

If GmaeScript is part of StarterGui, how will you get it through Server Storage?

0

GameScript is a localscript in the Startergui and WaitForChild returns an infinite yield and breaks the script.

1 answer

✓ Accepted answer

The problem is that you are using a local script to access a child of ServerScriptService. Only server-side scripts can access descendants of ServerScriptService, which explains why you are getting an error saying that the object doesn't exist; the object simply isn't replicated to the client. You will need to use remote functions / events to make this work.

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