Player.Name problem

local plr = game.Players.LocalPlayer
local DataStore = game:GetService("DataStoreService")
local TextService = game:GetService("TextService")

return function (context, target, text)

	game:GetService("ReplicatedStorage").Remotes.Notification:FireClient(target, text, plr.Name.." - DM!")

	return ("Command executed.")
	
end

Here is the error!

image

Is this in a module script or a local script?

This is a module script, that I have put it in.

Put it in starterplayerscripts.

yeah, make sure to put it inside the player

Then it would not work as it would be taken out of the commands folder.

So where is it currently stored? It’s the only way you can reference localplayer

The issue appears to be with plr.Name, meaning plr is nil. What does the Roblox wiki say about Players.LocalPlayer?

https://developer.roblox.com/en-us/api-reference/property/Players/LocalPlayer

  • This property is only defined for LocalScript s (and ModuleScript s required by them), as they run on the client. For the server (on which Script objects run their code), this property is nil.

wow, simple solution, local scripts can’t fire clients, only to server, instead handle the notification in the local script

You can’t reference “game.Players.LocalPlayer” inside a server script, instead get the player instance in some other way like from a fired “PlayerAdded” event etc. then use the player instance to get the name and then call FireClient() to fire the client.