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

How do I display a player's name after saying a sentence in Gui's? Please help correct my mistake

Just to give you a clip of what I mean, here's what I put down.

function OnClick()
	records.Visible = true
	records.Title = "History for "..player.Name..
end

Whenever I attempt to use that it errors with this: Expected identifier, got 'end' I did described what player was and all that was described but I can't get why it errors.

I did include additional things but only this part since it was the only part of the script that error'ed.

3 answers

✓ Accepted answer

You have an extra .. at the end of the line.

.. concatenates two strings -- one to the left and one to the right -- it "expected" another string to the right ('identifier'), but it got an "end" (on the next line)

Just

	records.Title = "History for " .. player.Name

will show "History for BlueTaslem", for instance.


This is a good reason it's standard practice to put spaces around everything. You'll notice things like the trailing .. much more easily.

1 comment

0

I commented that on Coolviper630's answer . Cheers

local player = game.Players.LocalPlayer -- ADD THIS
function OnClick()
    records.Visible = true
    records.Title = "History for "..player.Name..
end

6 comments

0

That is what I did. Still would get the error.

0

Did you put the event?

0

What event?

0

Why are you putting two ".." after the player.name? take that out. Also, make records a variable..

0

First did you add a variable for your button that is going to be clicked?

0

When someone asks a question, it's usually best at first to assume that everything they aren't showing is already correct. Saying things like "you didn't define player is almost surely not going to be helpful in this context.

First things first, you need to use the MouseButton1Click event which fires when you left click on the gui. I did this on the last line.

On the first three lines, I made variables which you will need to make this work. Change the variables parenting and such to be correct.

Now in the function I made the records gui visible and changed it's Text property to be the players name. Don't put two extra dots if you aren't going to Concate anymore.

You can read more on Concatenation here

local player = script.Parent.Parent
local gui = script.Parent:WaitForChild("ScreenGui"):WaitForChild("Gui")
local records = script.Parent:WaitForChild("ScreenGui"):FindFirstChild("records")
function OnClick()
    records.Visible = true
    records.Text= "History for "..player.Name
end

gui.MouseButton1Click:connect(OnClick)

4 comments

0

I did have a MouseButton1Click down at the bottom just didn't include that since it wasn't part of the error.

0

I assumed that! I always put more than necessary in my answers! I try my best to keep them high quality.

2

--It's always better to have an educated answer!

0

:3 That sounds like a good person.

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