You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? Keep it simple and clear!
A leaderboard for NPCs that shows how many rounds they survived.
What is the issue? Include screenshots / videos if possible!
When in a server or playtesting, it doesn’t appear, with a single error in the Client Console without any details.
What solutions have you tried so far? Did you look for solutions on the Creator Hub?
Tweaking sections of the code, yes.
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
local CollectionService = game:GetService("CollectionService")
local scrollingFrame = script.Parent
local npcLabelTemplate = script.NPC
local function onNpcAdded(npc)
if not npc:IsDescendantOf(workspace.AllBuilders) then
return
end
local npcLabel = npcLabelTemplate:Clone()
npc.Humanoid.Died:Once(function()
npcLabel:Destroy()
end)
local survivedTextLabel = npc.Head.ROUNDS.SURVIVED
local function updateLabel()
local roundsSurvived = tonumber(npc.Head.ROUNDS.SURVIVED.Text:match("%d+"))
if roundsSurvived then
npcLabel.Text = `{roundsSurvived}: {npc.Name}`
npcLabel.LayoutOrder = -roundsSurvived
end
end
npc.Head.ROUNDS.SURVIVED:GetPropertyChangedSignal("Text"):Connect(updateLabel)
updateLabel()
npcLabel.Parent = scrollingFrame
print("Added")
end
for _, npc in CollectionService:GetTagged("NPC") do
onNpcAdded(npc)
end
CollectionService:GetInstanceAddedSignal("NPC"):Connect(onNpcAdded)
Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.
A coder’s favorite thing to do, put prints in your function in different places. Start at the top of the local onNpcAdded function, and then move throughout it to make sure nothing is going on.
This looks like a ServerScript set up.. If you’re running this from ServerScriptService, GUI elements won’t appear. Use a LocalScript under the player’s GUI.
The logic and syntax look correct, but this is a ServerScript trying to manipulate GUI elements, which must be done in a LocalScript.
Okay then this should be a client sided script. I almost feel like it would be better if you handled all the round status on the server and then fire all clients with updates.
Sound like the NPC model doesn’t have a part named Head. Possibly check for Head before indexing..
if not npc:FindFirstChild("Head") then return end
if not npc.Head:FindFirstChild("ROUNDS") or not npc.Head.ROUNDS:FindFirstChild("SURVIVED") then return end
Also, the problem was fixed, however, the names of the NPCs dont seem to get ordered by how many rounds they have and theyre all put in the same position.
I was thinking you may be using a ragdoll death and lost your head..
Sorry, I’m a bit lost with what you’re doing here.. Anyways use a LocalScript when working with the player GUI. AC_Starmarine seems to understand what you’re doing a bit more than I do.. I’m going to back off.