Texture Won't Apply To Gun If Player Name Is Right

So, essentially, I’m trying to make a script so where if a player has a certain name, they’ll get a texture on the gun. I’ve tested it without the game.Players.LocalPlayer.Name and with basic variables. It works without any of that, it just stays the same texture if I add this.

My current script:

local function applyTextureToMeshParts(model)
	local gunStuff = model:GetDescendants()

	for i = 1, #gunStuff do
		if gunStuff[i]:IsA("MeshPart") then
			if game.Players.LocalPlayer.Name == "Comqts" then
				gunStuff[i].TextureID = "rbxassetid://11201026227"
			else
				gunStuff[i].TextureID = "rbxassetid://0"
			end
		end
	end
end

applyTextureToMeshParts(script.Parent)

3 Likes

can robolox studio change mesh textures while running the game

1 Like

I stated that it changed without the player.Name

2 Likes

i think your name is Comqts not Comqts try to change it

1 Like

I put it correctly. If it’s the wrong name, the texture should be 0

1 Like

just debug it using prints see where it all goes wrong

for i = 1, #gunStuff do
	if gunStuff[i]:IsA("MeshPart") then
        print(game.Players.LocalPlayer.Name)  
		if game.Players.LocalPlayer.Name == "Comqts" then
			gunStuff[i].TextureID = "rbxassetid://11201026227"
		else
			gunStuff[i].TextureID = "rbxassetid://0"
		end
	end
end

try this script i

local function applyTextureToMeshParts(model)
	local gunStuff = model:GetDescendants()

	for i = 1, #gunStuff do
		if gunStuff[i]:IsA("MeshPart") then
			if game.Players.LocalPlayer.Name == "Comqts" then
				gunStuff[i].TextureID = "rbxassetid://11201026227"
			else
				gunStuff[i].TextureID = "rbxassetid://0"
			end
		end
	end
end

applyTextureToMeshParts(script.Parent)

t should wor k

I think there is a typo in your code.

I think TextureID should be TextureId

image

Wait, when the script runs, the TextureID has changed, but the Texture stills being the same?

Your script unfortunately doesn’t work.

I’ve confirmed that I am able to change it whilst the game is active.

wait try this one this should work

local function applyTextureToMeshParts(model)
	local gunStuff = model:GetDescendants()

	for i = 1, #gunStuff do
		if gunStuff[i]:IsA("MeshPart") then
			if game.Players.LocalPlayer.Name == "Comqts" then
				gunStuff[i].TextureID = "rbxassetid://11201026227"
			else
				gunStuff[i].TextureID = "rbxassetid://0"
			end
		end
	end
end

applyTextureToMeshParts(script.Parent)

Nothing in there has been changed from my current script…

wait acuterly try this

local function applyTextureToMeshParts(model)
	local gunStuff = model:GetDescendants()

	for _,v in gunStuff do
		if gunStuff[i]:IsA("MeshPart") then
			if game.Players.LocalPlayer.Name == "Comqts" then
				gunStuff[i].TextureID = "rbxassetid://11201026227"
			else
				gunStuff[i].TextureID = "rbxassetid://0"
			end
		end
	end
end

applyTextureToMeshParts(script.Parent)

This code still doesn’t work unfortunately.

ok try this acuauacaccly

local function applyTextureToMeshParts(model)
	local gunStuff = model:GetDescendants()
print("I found the de")

	for _,v in gunStuff do
print("a de was found")
		if gunStuff[i]:IsA("MeshPart") then
print("I found the de mesh")
			if game.Players.LocalPlayer.Name == "Comqts" then
print("I found the him")
				gunStuff[i].TextureID = "rbxassetid://11201026227"
print("I changed the texture yooooo")
			else
print("I found the not him")
				gunStuff[i].TextureID = "rbxassetid://0"
print("I found the not him and change the texture yooooo")
			end
print("i dont know what function ended0")
		end
print("i dont know what function ended1")
	end
print("i dont know what function ended2")
end
print("i am DONE setting up the function now i will call it")

applyTextureToMeshParts(script.Parent)
print("ok i called it")

tell me what it printfs