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

Is this one of/the most optimal ways to add multiple overhead guis to a user's head?

SERVER SCRIPT

local Users = game:GetService("Players")

Users.PlayerAdded:Connect(function(User)
	local Char = User.Character or User.CharacterAdded:Wait()
	local Head = Char:WaitForChild("Head")

	for _, Tag in ipairs(script:GetChildren()) do -- the tags are the children of the script.
		local Clone = Tag:Clone()
		Clone.Parent = Head
		Clone.Adornee = Head
	end
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

2 comments

0

Is it a billboard gui? And where is this script located?

0

Billboard gui, and it's not "A", i said MULTIPLE. there is MULTIPLE overhead guis. that's why i'm using an ipairs loop.

1 answer

✓ Accepted answer

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:

local Users = game:GetService("Players")

Users.PlayerAdded:Connect(function(User)
	User.CharacterAdded:Connect(function(Char)
		-- do your thing
	end)
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.

1 comment

0

I specifically want it in the serverscriptservice, that's it generally. and omg thank you if i did not notice that...sdfjkhgshjsdga

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