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

How do I make text have a player name in it?

Asked by 4 years ago
Edited 4 years ago

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)
0
Your referencing startergui statergui is what gets cloned to player so on line 9 change startergui to playergui JesseSong 3916 — 4y

2 answers

Log in to vote
0
Answered by 4 years ago

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)
Ad
Log in to vote
0
Answered by 4 years ago
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.

0
It didn't work, and there's no error. Nothing happened. RobloxOplay0 0 — 4y
0
also i edited something if it helps RobloxOplay0 0 — 4y

Answer this question