I’m making a scrolling frame that displays all players in-game so you can select who to transfer money to. But I’m getting the error "Template is not a valid member of Script “Script” even though it is correctly parented.
This is what the code looks like:
local frame = script.Parent
local players = game:GetService("Players"):GetPlayers()
local ttype = Enum.ThumbnailType.HeadShot
local size = Enum.ThumbnailSize.Size420x420
local function update()
for _, child in ipairs(frame:GetChildren()) do
child:Destroy()
end
for _, player in ipairs(players) do
local clone = script.Template:Clone()
clone.Parent = script.Parent
clone.User.Text = player.Name
local id = player.UserId
local content = players:GetUserThumbnailAsync(id, ttype, size)
clone.Pic.Image = content
end
end
game:GetService("Players").PlayerAdded:Connect(update)
game:GetService("Players").PlayerRemoving:Connect(update)
update()
Could you show more of the ancestry of the script?
My suspicion is that the script is running before the template has loaded. Try using WaitForChild to see if this is the issue.
Your function destroys the Template object as a part of all children.
Give this a shot:
local function update()
for _, child in ipairs(frame:GetChildren()) do
if child.Name ~= "Template" then
child:Destroy()
end
end
for _, player in ipairs(players) do
local clone = script.Template:Clone()
clone.Name = "Clone"
clone.Parent = script.Parent
clone.User.Text = player.Name
local id = player.UserId
local content = players:GetUserThumbnailAsync(id, ttype, size)
clone.Pic.Image = content
end
end