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

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

Asked by
R0jym 47
2 years ago
Edited 2 years ago

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)
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 MarkedTomato 810 — 2y

1 answer

Log in to vote
0
Answered by 2 years ago
Edited 2 years ago
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

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 R0jym 47 — 2y
0
i started learning to script 5 days ago, im in the same boat as u dont sweat it lmao ZeroToH3ro 82 — 2y
Ad

Answer this question