SERVER SCRIPT
01 | local Users = game:GetService( "Players" ) |
02 |
03 | Users.PlayerAdded:Connect( function (User) |
04 | local Char = User.Character or User.CharacterAdded:Wait() |
05 | local Head = Char:WaitForChild( "Head" ) |
06 |
07 | for _, Tag in ipairs (script:GetChildren()) do -- the tags are the children of the script. |
08 | local Clone = Tag:Clone() |
09 | Clone.Parent = Head |
10 | Clone.Adornee = Head |
11 | end |
12 | end ) |
I want to ask because I've recently gained a lot of knowledge and would like to know if there is any better way to optimise/make this script more efficient. Please provide an answer if possible, thank you! <3
Well, you made a mistake in your script. It will add overhead guis once, but no more. You can test it. To make it work, you need to listen for another event Player.CharacterAdded
:
1 | local Users = game:GetService( "Players" ) |
2 |
3 | Users.PlayerAdded:Connect( function (User) |
4 | User.CharacterAdded:Connect( function (Char) |
5 | -- do your thing |
6 | end ) |
7 | end ) |
I personally prefer to move such scripts into a StarterPlayer.StarterCharacterScripts
to clean other folders from scripts, but I am not sure if it's the most efficient way, but doing so you don't need to bother about listening to events and cloning things.