Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Help with texture changing onclick?

Asked by
yoshi8080 445 Moderation Voter
9 years ago

I wanted the part to change textures onclick but, it won't even change?

local gift = script.Parent.Parent.Gift
local mesh = gift.Mesh
local texture = mesh.TextureId
local right = script.Parent.Parent.Right
local click = right.ClickDetector
local id = "rbxassetid://"
local sn = 1
texture = {189748284,189783253 }
function onClicked()        
sn = sn + 1
    if sn > #texture then sn = 1 end
    texture = id..texture[sn]
end
for i=1,#texture do
    print(i)
end

 script.Parent.ClickDetector.MouseClick:connect(onClicked)

Error:attempt to concatenate field '?' (a nil value) help with explainations please?

1 answer

Log in to vote
0
Answered by
nilVector 812 Moderation Voter
9 years ago

One of your problems is here:

local texture = mesh.TextureId

texture will be a String. It does not reference to the textureId property of the mesh. You can't create a reference to a property of an object and expect to change it later on. Whenever you need to change the textureId of the mesh, you have to do something like this in your case (on line 12):

mesh.textureId = id..texture[sn]

Another problem is that you first initialized texture to be the textureId, but later, you created a table of two Integers with the same exact name. The script cannot understand which texture variable you're trying to talk about.

Simply get rid of the first texture variable and use mesh.textureId method, and that should fix all your problems.

0
Thanks so much c: yoshi8080 445 — 9y
Ad

Answer this question