Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
-1

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

Asked by 9 years ago

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

Log in to vote
2
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
9 years ago

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.

0
I commented that on Coolviper630's answer . Cheers Thetacah 712 — 9y
Ad
Log in to vote
0
Answered by 9 years ago
local player = game.Players.LocalPlayer -- ADD THIS
function OnClick()
    records.Visible = true
    records.Title = "History for "..player.Name..
end
0
That is what I did. Still would get the error. ChefBuckeye 0 — 9y
0
Did you put the event? Coolviper630 95 — 9y
0
What event? ChefBuckeye 0 — 9y
0
Why are you putting two ".." after the player.name? take that out. Also, make records a variable.. Thetacah 712 — 9y
View all comments (2 more)
0
First did you add a variable for your button that is going to be clicked? Coolviper630 95 — 9y
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. BlueTaslem 18071 — 9y
Log in to vote
0
Answered by
Thetacah 712 Moderation Voter
9 years ago

First things first, you need to use the MouseButton1Click event which fires when you left clickon 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)
0
I did have a MouseButton1Click down at the bottom just didn't include that since it wasn't part of the error. ChefBuckeye 0 — 9y
0
I assumed that! I always put more than necessary in my answers! I try my best to keep them high quality. Thetacah 712 — 9y
2
--It's always better to have an educated answer! Thetacah 712 — 9y
0
:3 That sounds like a good person. ChefBuckeye 0 — 9y

Answer this question