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)
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.