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

How do I Move Local Scripts?

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)

5 comments

0

Please format your code in Lua Code block.

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.

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)

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

0

Lol when it says consider changing it to local, it means a local variable. Not a local script.

1 answer

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)

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