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

?Expected identifier when parsing expression [

im making a gui where you can type a brick name, and a text and it displays text on the selected brick using replicated storage.

function click()
    
    local custom = script.Parent.Parent.CustomName.Text
    
    local text = script.Parent.Parent.CustomText.Text
    local part = game.Workspace[custom]
    
    local part1 = workspace:FindFirstChild([custom].SurfaceGui)
    if part1 then
        custom:FindFirstChild("SurfaceGui")
    end
    
    game.ReplicatedStorage.SurfaceGui:Clone().Parent = workspace[custom]
    game.Workspace[custom].SurfaceGui.TextLabel.Text = text
end



script.Parent.MouseButton1Click:Connect(click)

if you place a gui on a brick more than once, i want it to delete the old one. thats what the findfirstchild is for, then i will remove the first child. error was Expected identifier when parsing expression [ in line 7. its trying to find custom in the workspace. (which is a variable)

1 answer

✓ Accepted answer

I'm pretty sure that you aren't supposed to use brackets when also using FindFirstChild because they do basically the same thing.

Try this:

function click()

    local custom = script.Parent.Parent.CustomName.Text

    local text = script.Parent.Parent.CustomText.Text
    local part = game.Workspace[custom]

    local part1 = workspace:FindFirstChild(custom)

    game.ReplicatedStorage.SurfaceGui:Clone().Parent = workspace[custom]
    game.Workspace[custom].SurfaceGui.TextLabel.Text = text
end



script.Parent.MouseButton1Click:Connect(click)

Or if the SurfaceGui were to stay, you would do:

function click()

    local custom = script.Parent.Parent.CustomName.Text

    local text = script.Parent.Parent.CustomText.Text
    local part = game.Workspace[custom]

    local part1 = workspace:FindFirstChild(custom).SurfaceGui --This is the gui, not the part

    game.ReplicatedStorage.SurfaceGui:Clone().Parent = workspace[custom]
    game.Workspace[custom].SurfaceGui.TextLabel.Text = text
end



script.Parent.MouseButton1Click:Connect(click)

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