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 :
1 | game.Players.PlayerAdded : connect ( function (player) |
2 | ls = game.ServerScriptService.LocalScript : clone () |
3 | ls.Parent = Player.Character |
4 | end ) |
When I found that the above script didn't work, I attempted to fix it on my own:
1 | game.Players.PlayerAdded : connect ( function (player) |
2 | player = game.ServerScriptStorage.LocalScript : clone () |
3 | player.Parent = game.Players.LocalPlayer.Character |
4 | end ) |
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.
1 | local Storage = game:GetService( "ServerStorage" ) -- Just a storage, you do not need to add this. |
2 | 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. |
3 |
4 | game.Players.PlayerAdded:connect( function (Player) -- When the player joins... |
5 | wait() -- We wait because the Character might actually not exist yet... |
6 | local Character = Player.Character -- Before we check for the Character.... |
7 | Script:clone().Parent = Character -- And give it a clone of the script. |
8 | end ) |