So in my script, I’m cloning a frame with a UIListLayout. Inside of the frame is a TextButton with some things in it. Basically, after cloning the Frame, it says in my output ‘RoleTextButton is not a valid member of Frame “DisplayFrame”’. I’ll attach my script below, along with the part of the script that is causing the error. Any help is appreciated
Part of the script causing the error:
local newButton = template:Clone()
newButton.RoleTextButton.Name = role.Name
newButton.RoleTextButton.NameTextLabel.Text = role.Name
newButton.RoleTextButton.BackgroundColor3 = config.Color.Value
newButton.RoleTextButton.CharacterImage.Image = config.ImageLabel.Image
newButton.RoleTextButton.MouseButton1Click:Connect(function()
if selectedButton == newButton then
return end
if selectedButton then
selectedButton.BackgroundColor3 = Color3.new(selectedButton.BackgroundColor3.R + 0.2, selectedButton.BackgroundColor3.G + 0.2, selectedButton.BackgroundColor3.B + 0.2)
titleText.Text = selectedButton.Name
previewFrame.CharacterPreview.Image = config.PreviewImage.Image
config.SelectionSound:Play()
end
selectedButton = newButton
selectedButton.BackgroundColor3 = Color3.new(selectedButton.BackgroundColor3.R + 0.2, selectedButton.BackgroundColor3.G + 0.2, selectedButton.BackgroundColor3.B + 0.2)
end)
table.insert(roleButtons, newButton)
end
The whole script:
local template = script:WaitForChild("DisplayFrame")
local rs = game:GetService("ReplicatedStorage")
local roles = rs:WaitForChild("Roles")
local remotes = rs:WaitForChild("RemoteEvents")
local gui = script.Parent
local previewFrame = gui.RoleSelectorFrame:WaitForChild("PreviewFrame")
local titleText = gui.RoleSelectorFrame:WaitForChild("TitleTextLabel")
local roleButtons = {}
local selectedButton = nil
for _, role in pairs(roles:GetChildren()) do
local config = role.Configuration
local newButton = template:Clone()
newButton.RoleTextButton.Name = role.Name
newButton.RoleTextButton.NameTextLabel.Text = role.Name
newButton.RoleTextButton.BackgroundColor3 = config.Color.Value
newButton.RoleTextButton.CharacterImage.Image = config.ImageLabel.Image
newButton.RoleTextButton.MouseButton1Click:Connect(function()
if selectedButton == newButton then
return end
if selectedButton then
selectedButton.BackgroundColor3 = Color3.new(selectedButton.BackgroundColor3.R + 0.2, selectedButton.BackgroundColor3.G + 0.2, selectedButton.BackgroundColor3.B + 0.2)
titleText.Text = selectedButton.Name
previewFrame.CharacterPreview.Image = config.PreviewImage.Image
config.SelectionSound:Play()
end
selectedButton = newButton
selectedButton.BackgroundColor3 = Color3.new(selectedButton.BackgroundColor3.R + 0.2, selectedButton.BackgroundColor3.G + 0.2, selectedButton.BackgroundColor3.B + 0.2)
end)
table.insert(roleButtons, newButton)
end
table.sort(roleButtons, function(a, b)
return a.Name < b.Name
end)
for _, button in pairs(roleButtons) do
script.DisplayFrame.Parent = script.Parent.RoleSelectorFrame.RolesScrollingFrame
end
script.Parent.RoleSelectorFrame.DeployTextButton.MouseButton1Click:Connect(function()
if selectedButton then
remotes.ChooseRole:FireServer(selectedButton.Name)
end
end)