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 make text have a player name in it?

How do I make text have a player name in it? I'm trying to make a script that says something like "(name) won!" but it does nothing. Here's the code I have.

local Players = game:GetService("Players")
local part = script.Parent
local player = Players:GetPlayerFromCharacter(part.Parent)
local debounce = false
game.Workspace.epicBrick.Touched:Connect(function(hit)
if not debounce then
	debounce = true

bc = BrickColor.new("New Yeller")
game.StarterGui:SetCore("ChatMakeSystemMessage", {
	Text = player.Name .. " won!"; --error here?
	Font = Enum.Font.SourceSansBold;
	Color = bc.Color;
	FontSize = Enum.FontSize.Size32;	
})
wait(5)
debounce = false
end	
end)

When I playtest the game and touch the brick called "epicBrick", nothing happens. When I remove "player.Name" from the error line, it types " won!" in chat, but without the player name.

Edit: Changed to this because it could be better than the last version to see issues. I still can't figure it out though. New Version:

local character = game.Workspace.Player
local player = game.Players:GetPlayerFromCharacter(character)
local debounce = false
game.Workspace.epicBrick.Touched:Connect(function(hit)
if not debounce then
    debounce = true

bc = BrickColor.new("New Yeller")
game.StarterGui:SetCore("ChatMakeSystemMessage", {
    Text= player.Name .." won!"; --error here?
    Font = Enum.Font.SourceSansBold;
    Color = bc.Color;
    FontSize = Enum.FontSize.Size32;    
})
wait(5)
debounce = false
end 
end)

1 comment

0

Your referencing startergui statergui is what gets cloned to player so on line 9 change startergui to playergui

2 answers

✓ Accepted answer

Hello.

Problem:

Instead of using GetPlayerFromCharacter(), just use game.Players.LocalPlayer.

Fixed Code:

local Players = game:GetService("Players")
local part = script.Parent
local player = game.Players.LocalPlayer
local debounce = false
game.Workspace.epicBrick.Touched:Connect(function(hit)
if not debounce then
    debounce = true

bc = BrickColor.new("New Yeller")
game.StarterGui:SetCore("ChatMakeSystemMessage", {
    Text = player.Name .. " won!"; --error here?
    Font = Enum.Font.SourceSansBold;
    Color = bc.Color;
    FontSize = Enum.FontSize.Size32;    
})
wait(5)
debounce = false
end 
end)
local Players = game:GetService("Players")
local part = script.Parent
local player = Players:GetPlayerFromCharacter(part.Parent)
local debounce = false
game.Workspace.epicBrick.Touched:Connect(function(hit)
if not debounce then
    debounce = true

bc = BrickColor.new("New Yeller")
game.StarterGui:SetCore("ChatMakeSystemMessage", {
    Text = player.Name .." won!"; --error here? there was a space here
    Font = Enum.Font.SourceSansBold;
    Color = bc.Color;
    FontSize = Enum.FontSize.Size32;    
})
wait(5)
debounce = false
end 
end)

The space could've been causing it, maybe. Try that, and if it doesn't work, copy and paste the error into a comment below this.

2 comments

0

It didn't work, and there's no error. Nothing happened.

0

also i edited something if it helps

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