Putting LocalScripts onto the client from a server script?

Hi!

My system is being loaded in a few seconds after the game loads, and players are in it. Basically like HD Admin and Adonis, I need to load scripts permanently to the player without using StarterPlayerScripts.

At the moment I use PlayerGui, which works until they reset.
Do I just use a CharacterAdded event, or is there something better?
Thanks in advance.

– This is an external module, so I cannot use StarterPlayerScripts, StarterGui etc…

I think if you make a Screen GUI, set Reset On Spawn to false and then just put your local script in then, it should work
(I think so cause it happened to break my game when I did Reset In Spawn cause my local scripts couldn’t find the character it was parented to)

But there’s probably a better way to do it just my suggestion

1 Like

I was hoping for something more efficient than PlayerGui but I’ll do this as a fallback plan.
Thanks

Just insert the object you want to into the PlayerScripts when the player joins:

game.Players.PlayerAdded:Connect(function(plr)
    local PlayerScripts = plr:WaitForChild("PlayerScripts")
    local Object = -- the path to your object
    Object:Clone().Parent = PlayerScripts

end)

This is more efficient than @Vikram200526 s solution

The server cannot access PlayerScripts. Please read the question.

For one, why bump a topic this old, just dm me.

And secondly, that code works. When the player joins, we grab the player, then we get their play script directly. Please do some research before claiming things like this.

1 Like

It does not work in a server-sided Script as they asked in the title of this question, please try it yourself.
Infinite yield possible on 'Players.VilgotanL:WaitForChild("PlayerScripts")'

Well, I really don’t understand why you need this, but I believe it’s enough to just set the LocalScript Parent to the Player Backpack. It is necessary to bear in mind that after the player resets his character, the script will no longer exist, so you will have to take some measures, such as identifying every time the Character is added and thus defining the script for the player’s Backpack again.

--// Services
local Players = game:GetService('Players')

--// Script
local LocalScript = script:FindFirstChild('LocalScript')

--// Functions
function PlayerAdded(player: Player)
    local client = LocalScript:Clone()
    client.Parent = player:FindFirstChild('Backpack')
end

--// Connections
Players.PlayerAdded:Connect(PlayerAdded)
1 Like