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

How do I Move Local Scripts?

Asked by 9 years ago

I'm attempting to move a Local Script from ServerScriptService to a player once they join but keep running into road blocks. Someone tried to help me out by giving me this script :

game.Players.PlayerAdded : connect (function(player)
    ls = game.ServerScriptService.LocalScript : clone ()
    ls.Parent = Player.Character
end)

When I found that the above script didn't work, I attempted to fix it on my own:

game.Players.PlayerAdded : connect (function(player) 
    player = game.ServerScriptStorage.LocalScript : clone ()
    player.Parent = game.Players.LocalPlayer.Character
end)
0
Please format your code in Lua Code block. Goulstem 8144 — 9y
0
The first script will work perfectly fine as long as you have the names and everything correct. Just make sure that that isn't your problem, and try to run it again. Also, in just in case, make sure that the problem isn't simply that the LocalScript doesn't do anything to alert you to it's presence. Check to make sure that it was moved in the Explorer. dyler3 1510 — 9y
0
When ever I try and use the first code, I keep getting a blue line under "ls" stating that its only used in the enclosing function, consider changing it to local (which I have attempted :c) CaptSmoker 5 — 9y
0
Whenever the lua debugger says that then it's just suggesting you turn x = "code" into local x = "code" so it's not the script breaking Goulstem 8144 — 9y
0
Lol when it says consider changing it to local, it means a local variable. Not a local script. CodingEvolution 490 — 9y

1 answer

Log in to vote
0
Answered by
pyro89 50
9 years ago

Well, the ServerScriptService is meant mainly to be used as a backup to the Workspace as a storage for scripts. You know how you might always see Scripts in the Workspace? Just move them to the ServerScriptService and they'll work from there. But, as a Local Script, it might not function as well. Instead, you can move it to ServerStorage, or ReplicatedStorage if you are planning to use it from GUIs and things.

local Storage = game:GetService("ServerStorage") -- Just a storage, you do not need to add this.
local Script = Storage:WaitForChild("LocalScript") -- To refer to the Script more easily instead of looking for this one script named LocalScript every time a player joins.

game.Players.PlayerAdded:connect(function(Player) -- When the player joins...
    wait() -- We wait because the Character might actually not exist yet...
    local Character = Player.Character -- Before we check for the Character....
    Script:clone().Parent = Character -- And give it a clone of the script.
end)
Ad

Answer this question