Hi, So i'm writing this script that changes the decal texture asset ID of a part called "Screen". I've made loads of different stringvalues (one, two, three) which each have their own asset ID link (eg. http://www.roblox.com/asset/?id=238110849) i'm quite sure the links are ok. The hierarchy is:
Model, one, two, three, four, five, six, seven, eight, Part (ClickDetector, Script), Sign (PointLight, Decal)
Here's the script:
01 | isOn = 0 |
02 | local a = script.Parent.Parent.one.Value |
03 | local b = script.Parent.Parent.two.Value |
04 | local c = script.Parent.Parent.three.Value |
05 | local d = script.Parent.Parent.four.Value |
06 | local e = script.Parent.Parent.five.Value |
07 | local f = script.Parent.Parent.six.Value |
08 | local g = script.Parent.Parent.seven.Value |
09 | local h = script.Parent.Parent.eight.Value |
10 | local sign = script.Parent.Parent.Sign.Decal.Texture |
11 |
12 | function three() |
13 | do sign = "" ..a |
14 | isOn = 2 |
15 | end |
I know it's unnecessarily long but I made the original a while ago and just edited that.
You change the variable sign
, but only the variable sign
.
All that does is overwrite sign
with the new texture. That doesn't change the texture of script.Parent.Parent.Sign.Decal
.
You have to explicitly change a property to change the property:
1 | local decal = script.Parent.Parent.Sign.Decal |
2 |
3 | ...... |
4 |
5 | decal.Texture = f -- or whatever else here |
Let's fix this code, though. Instead of having a bunch of variables, make a list:
01 | local list = { |
02 | script.Parent.Parent.one.Value, |
03 | script.Parent.Parent.two.Value, |
04 | script.Parent.Parent.three.Value, |
05 | script.Parent.Parent.four.Value, |
06 | script.Parent.Parent.five.Value, |
07 | script.Parent.Parent.six.Value, |
08 | script.Parent.Parent.seven.Value, |
09 | script.Parent.Parent.eight.Value |
10 | } |
Now it's easy to do the rest:
01 | local shown = 1 |
02 |
03 | -- Advance to the next one |
04 | function advance() |
05 | shown = shown + 1 -- Got to the next one |
06 | if shown > #list then |
07 | -- I'm past the end -- start over at 1 |
08 | shown = 1 |
09 | end |
10 | -- (or you can fiddle with mods to get this to one line of code) |
11 | end |
12 |
13 | -- Show the currently selected slide |
14 | function show() |
15 | decal.Texture = list [ shown ] |
Your problem is that you're attempting to edit a property directly from a variable
This won't work, you have to make the variable
the object that the property is tied to, then edit the variable
by indexing the property
.
Also, your script has so many unnecessary aspects to it. Just make a table
containing all of the values, then use your int variable to index the table.
01 | local num = 0 |
02 | local sign = script.Parent.Parent.Sign.Decal |
03 | local vals = { --Table full of all the values |
04 | script.Parent.Parent.one, |
05 | script.Parent.Parent.two, |
06 | script.Parent.Parent.three, |
07 | script.Parent.Parent.four, |
08 | script.Parent.Parent.five, |
09 | script.Parent.Parent.six, |
10 | script.Parent.Parent.seven, |
11 | script.Parent.Parent.eight |
12 | } |
13 |
14 | function incrementDecal() |
15 | if num = = #vals + 1 then num = 0 end --reset if it's at limit |
Your script is just over-complicated, which makes it easier to get errors. It would be much simpler to store all the string values into a table, and then having a variable that gets incremented by 1 every time the button is clicked. That way, you can use that variable to get the corresponding element in the table. Like so:
01 | local Index = 1 --This is the index variable. It will be used to get the corresponding element from the table below |
02 | local Textures = { --This table contains the textureId's for the decals. You can also replace the "script.Parent.Parent.one.Value" with the actual value of One, and do the same for the rest of them |
03 | script.Parent.Parent.one.Value; |
04 | script.Parent.Parent.two.Value; |
05 | script.Parent.Parent.three.Value; |
06 | script.Parent.Parent.four.Value; |
07 | script.Parent.Parent.five.Value; |
08 | script.Parent.Parent.six.Value; |
09 | script.Parent.Parent.seven.Value; |
10 | script.Parent.Parent.eight.Value; |
11 | } |
12 | local Sign = script.Parent.Parent.Sign.Decal --The sign variable has to be the decal, not the texture of the decal because the texture of the decal is what you're trying to change. If Sign was the decal's texture, then whenever you said "Sign = ...", that would change the variable, not the texture |
13 |
14 | function onClicked() |
15 | Sign.Texture = Textures [ Index ] --This sets the textureId of the decal to the Index'th element of the table "Textures" |
Hope this helped!