How can you set a meshes Texture to a different texture using a script?

I wrote this script but it deosn’t work

while true do
	script.Parent.TextureId = "rbxassetid://13078612043"
	wait(.2)
	script.Parent.TextureId = "rbxassetid://13078696118"
	end
1 Like

Hi, here to help!

  1. What doesn’t work? Does the script give an error, behave unexpectedly, or does nothing? Please elaborate on that one.
  2. Are you sure that script.Parent is a Mesh? Could the script be parented to something else by accident?
1 Like

Nope, there are no errors and the parent is in fact a mesh.

Since I don’t know the expected behavior here’s my assumption. I assume that by making a while loop, you’re trying to switch back and forth between these textures every 0.2 seconds. But only one texture is ever set because you need two wait(0.2) calls in your script, one after both of the texture changes. That’s because, by only having one wait(), you’re letting one texture set, then the script waits .2 seconds, sets the second texture and then immediately goes back to the first one (according to the while loop). Try something like this:

while true do
	script.Parent.TextureId = "rbxassetid://13078612043"
	wait(.2)
	script.Parent.TextureId = "rbxassetid://13078696118"
	wait(.2)
end
1 Like

Roblox saves the mesh’s data on the user’s device and to avoid a developer completely destroying the user’s device - by continuously changing the mesh -, they don’t give us the ability to edit a mesh’s texture from scripts.

They may have added support for this without me noticing but that is the answer most probably.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.