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

Why wont a Players name be put into TextLabel?

I'm currently working on a scrip that fires a client when a player dies and sends the name of the player who died and sends the player's killer but for some reason, I'm unable to put the player's name into a text label, and I know it's not an issue from the server I've tested the server 3 times with prints so I'm suspecting from the print testing and the error I get that it's from the client

Players.Player2.PlayerGui.MenuHandler.KillStats:60: invalid argument #3 (string expected, got nil)

ReplicatedStorage:FindFirstChild("Events").KillStatsUI1.OnClientEvent:Connect(function(Player, Playername)
	local KillStatsClone1 = KillPopUp:Clone() ---everything except the 5 line works.
	KillStatsClone1.Parent = script.Parent.MainGui
	KillStatsClone1.Total.Text = "50"
	KillStatsClone1.PlayerName.Text = Playername
end)

1 comment

0

Are you firing the player or player.Name?

1 answer

✓ Accepted answer

Problem

This is a misunderstanding of RemoteEvents with the :FireClient() and .OnClientEvent.

The first argument of :FireClient() is the player you want to fire to, and arguments after the first are other arguments you want to pass to the LocalScript. It looks like this.

Script

RemoteEvent:FireClient(MarkedTomato, 2, 4)

LocalScript

RemoteEvent.OnClientEvent:Connect(function(num1, num2)
   print(num1) --prints 2
   print(num2) --prints 4
end)

If you still don't understand, you can look at the description of the parameters of :FireClient() here.

Your actual error means that it expected a string but got nil, nil meaning nothingness.

Solution

Make a variable for the LocalPlayer.

Fixed LocalScript

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

ReplicatedStorage:FindFirstChild("Events").KillStatsUI1.OnClientEvent:Connect(function()
    local KillStatsClone1 = KillPopUp:Clone()

    KillStatsClone1.Parent = script.Parent.MainGui
    KillStatsClone1.Total.Text = "50"
    KillStatsClone1.PlayerName.Text = player.Name
end)

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