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

Where can Scripts/LocalScripts run?

Asked by
novipak 70
10 years ago

Well, I've had a bit of an issue lately.

I've written a little script that should be running, but it's not.

I'll try to explain what's happening briefly, as some of this may or may not be relevant: I have a server script in Workspace that clones a bunch of folders, parented to one folder into the player. In this group of folders there is a localscript with this simple code:

wait(1)
script.Parent.DescendantAdded:connect(function(new)
    print("Added ")
end)

that should run when I insert something from ServerStorage into the folders.

Here's what the folders look like, for a better idea: http://gyazo.com/e53b1df071d997f0efa348f2220eff90

I've tried this in localscripts, scripts, and I've tried some different events, but it seemed more like the scripts just aren't running. So I'm wondering, why is my script not working? Can localscripts and/or scripts only be ran from certain places?

Thanks for reading, I know it's very trivial but it would help a ton if we could figure out a solution to this. I feel like I might be messing up something painfully obvious, aha.

0
The LocalScript will not fire if it is parented to Player, or a descendent of Player. PlayerGui must be an ancestor of the LocalScript. duckwit 1404 — 10y

2 answers

Log in to vote
1
Answered by
Redbullusa 1580 Moderation Voter
10 years ago

LocalScripts will function if it is placed within one of three areas (or, at least, is a descendant of the three):


What I would do is disable the local script, then, somewhere in your server script after the line where the folder gets parented, add this bit of code:

Folder:WaitForChild("item_checker").Disabled = false
-- Or whatever variable you assigned your folder to.

Because local scripts are client-sided, it will not run in anywhere else except for the aforementioned locations.

I hope this helps. If it doesn't, tell me and I will give it another look.

0
Thanks a lot! I figured it wasn't running. This will help a lot. novipak 70 — 10y
Ad
Log in to vote
1
Answered by 10 years ago

ServerScripts can work in game.Workspace, game.ServerScriptService, a Player's backpack, a Player's PlayerGui, and game.ReplicatedFirst. LocalScripts can be used in these parts, but run on the client side. I like to use LocalScripts to get the player (game.Players.LocalPlayer) and to get the mouse of the player (game.Players.LocalPlayer:GetMouse()). LocalScripts can also run inside a player's character. I hope this helped!

Answer this question