Need help finding the name of the LocalPlayer

I am trying to make a script inside the Default Roblox sword that changes the texture of the sword IF the person holding it has a specific name.

My issue is that I do not know what to do here, I have tried to find the name of the player by doing a simple “if LocalPlayer.Name == sirvko then”, but that results in a “Attempting to Index nil” error.
I have also tried to do the same thing but for the character instead of the player, but the same thing happened.

This is my first time posting on the DevForum, and I am not a very good scripter.

Code:

local players = game:GetService("Players")
local sirvkoplayer = players.LocalPlayer

if sirvkoplayer.Name == "sirvko" then
	script.Parent.Handle.Mesh.TextureId = "rbxassetid://10169518111"
end
3 Likes

If this is NOT a local script you can NOT use game.Players.LocalPlayer

Use the GetPlayerFromCharacter() function. It gets the player of the current character.

1 Like

Make sure the name is in quotation marks and parentheses and that it is in a local script.

(“Name”)

That worked! Thanks, I did not know that you needed parentheses to get a name.

1 Like

No problem! Glad it works now! :slight_smile: