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

How to make TextLabel to copy the player's name who pressed the button?

Hello there, I have a LocalScript I made where the script is supposed to change the TextLabel like this:

"R0jym has rolled 4"

However it does not seem to work, as the output keeps saying that it's an error and the script keeps considering the PlayerName as a string, how do I remedy this? Thanks for any help

local player = game:GetService("Players").LocalPlayer

local PlayerName = player.DisplayName
local RS = game:GetService("ReplicatedStorage")
local AnnounceEvent = RS:WaitForChild("AnnounceEvent")
local text = player.PlayerGui.Announce.TextLabel
local text2 = player.PlayerGui.Roll.TextLabel
local button = player.PlayerGui.Roll.TextButton
local value = player.PlayerGui.Roll.Value

button.MouseButton1Click:Connect(function()
	text.Text = ..PlayerName 'has rolled '..text2.Text
	AnnounceEvent:FireServer()
end)

1 comment

0

You should tell us your error message as it'll help us find a solution to your problem. I see a problem on line 12 you put two dots to the left of PlayerName while it should be on the right of PlayerName

1 answer

✓ Accepted answer
local player = game:GetService("Players").LocalPlayer

local PlayerName = player.DisplayName
local RS = game:GetService("ReplicatedStorage")
local AnnounceEvent = RS:WaitForChild("AnnounceEvent")
local text = player.PlayerGui.Announce.TextLabel.Text --changed this for u
local text2 = player.PlayerGui.Roll.TextLabel.Text --changed this too
local button = player.PlayerGui.Roll.TextButton
local value = player.PlayerGui.Roll.Value

button.MouseButton1Click:Connect(function()
	text = PlayerName ..' has rolled '..text2 --this should work now
	AnnounceEvent:FireServer()
end)

also, u have too many useless variables imo & consider using WaitForChilds when dealing with playerGui

2 comments

0

I'm quite new to scripting and I'm not really consistent at organizing anything in my entire life so I verily apologize if it looks like I have too many useless variables

0

i started learning to script 5 days ago, im in the same boat as u dont sweat it lmao

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