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 the LocalPlay not nil?

I have this chat, when the player types something and presses enter, it fires a remote event then that fires one back to the client making the player's chat show on the players gui. When it is fired and I do this script says the Player.Name is nil.

game.ReplicatedStorage.ServerStats.CustomChat.ChattedOut.OnClientEvent:connect(function(Player, Text)
  
  if game.ReplicatedStorage.PlayerStats:FindFirstChild(game.Players.LocalPlayer.Name) and game.ReplicatedStorage.PlayerStats:FindFirstChild(game.Players.LocalPlayer.Name).BlockedList:FindFirstChild(Player.Name) == nil then
    local Location = "N/A"
    if game.ReplicatedStorage.PlayerStats:FindFirstChild(Player.Name) then
      Location = game.ReplicatedStorage.PlayerStats:FindFirstChild(Player.Name).Location.Value
	end

2 answers

✓ Accepted answer

You seem to be sending the Player object yourself to the client from the server. You cannot send instances between computers, only tables (more specifically, dictionaries with string keys and arrays), numbers, strings, and datatypes.

Instead of sending Player, just send Player's Name, since that's all you're using anyway.

EDIT: And please, instead of going game.Players.LocalPlayers.Name all the time, just store the name in a variable!

This code looks like it's an a Script.

A Script runs on the server as a whole. ROBLOX is a multiplayer game -- on the server, there is no "local player". As the Wiki clearly documents, you can only use LocalPlayer from a LocalScript.

You use Player.Name in a few of the places, which is what you should be using. You shouldn't have any reference to a "LocalPlayer" in this script.


Indent your code correctly. Use tabs, and exactly one tab per group of statements, no more, no less.

Avoid long lines and expressions.

  • game.ReplicatedStorage.PlayerStats can be saved to a variable, e.g., PlayerStats
  • PlayerStats:FindFirstChild(Player.Name) can be saved to a variable

1 comment

0

It is a local script

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