Help " invalid argument #2 (string expected, got nil) " script changing shirt of LocalPlayer

I made a script for change the Local Player shirt and doesn’t work, please, if you know how to make it work reply this message.


The code:
--Variables:

local P = game.Players.LocalPlayer
local PN = P.Name
local PNS = PN.Shirt
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local comprar = script.Parent.Comprar
local costeP = script.Parent.CosteP
local nombreP = script.Parent.NombreP
local prenda = script.Parent.Prenda
local productID = 7337672531 -- ID de tu prenda
local CerrarG = script.Parent.CerrarGUI
local probarP = script.Parent.ProbarP

--




--Codigo:


-- Borrar GUI con la " X " 

CerrarG.MouseButton1Click:Connect(function()
	
script.Parent:Destroy()
	
end)

--

---

-- Mostrar ropa en ImagenLabel:

probarP.MouseButton1Click:Connect(function()
	
	game.Workspace[PNS].ShirtTemplate = "http://www.roblox.com/asset/?id=7337672531"

		
end)



--

---

--

Yeah, if you know what is the error of " invalid argument #2 (string expected, got nil) " please reply this message.

error:
image

BTW, all of these variables will be used in the future.

I don’t understand why you’re indexing Shirt from game.Players.LocalPlayer.Name. The issue is that P.Name conflicts with an attribute and a child, if I assume that there is a child of LocalPlayer that is named Name.

3 Likes

i put

local PNS = PN.Shirt

Because I will be using PN with other things that are not related with the LocalPlayer name.

You want P.Character in this case

You were right buddy! Thanks you alot !

1 Like