I'm a little stumped on how to do this, so maybe you all can help?
I have a zone set up where if you enter/exit it, it sends a message to the server. I want to have it where when you enter, it rolls a random number between 1-6 (which has already been configured) but I'm unsure of how to make it where a decal on a part will change depending on what number it is. Thanks!
#Change decal when receiving random number
28 messages · Page 1 of 1 (latest)
Just store decals in a table or an instance and before returning the random number you apply the ID of the decal to that part.
So, i assume you have the random number in a variable like this:
local rng = math.random(1, 6)
Now, as he says you just need a table like this with the ID’s of the decals.
local Decals = {"rbxassetid://[ID_OF_DECAL]", "rbxassetid://[ID_OF_DECAL]", "rbxassetid://[ID_OF_DECAL]", "rbxassetid://[ID_OF_DECAL]", "rbxassetid://[ID_OF_DECAL]", "rbxassetid://[ID_OF_DECAL]"}
local rng = math.random(1, 6)
And then you just use the rng to find the correct decal!
local Decals = {"rbxassetid://[ID_OF_DECAL]", "rbxassetid://[ID_OF_DECAL]", "rbxassetid://[ID_OF_DECAL]", "rbxassetid://[ID_OF_DECAL]", "rbxassetid://[ID_OF_DECAL]", "rbxassetid://[ID_OF_DECAL]"}
local rng = math.random(1, 6)
workspace.Part.Decal.ImageId = Decals[rng] ——indexing like this takes the first decal id if the rng is 1, the second decal id if the rng is 2 etc.
Almost correct
Wdym?
whats wrong?
Yes, i dont know what the property of decals are called
So i took a guess
You can remove the repeated part rbxassetid:// from the table, it's only needed at the end when setting the image:
Decal.Texture = "rbxassetid://" .. Decals[rng]
This saves up a tiny bit of memory and some people's eyes from suffering.
@soft hare
Oh and don't worry I forgot as well
Omg thanks!!!!
I'll try it out today
For reference it's an npc where if you walk into his room he could he happy, angry, yadayadayada, so on and so forth. Would there be a way to match up voice lines as well? just add that to a new table?
** You are now Level 4! **
Did it work?
How I was attempting to set it up before is
npcopenmouth = workspace.npc.head.openmouthimage
npcclosedmouth = workspace.npc.head.closedmouth image
entrynumber = math.random(0,6)
Then, I have a zones code to allow me to monitor when people enter zones, so off the top of my head it's something like,
playerenterzone __
print("% has entered the zone!"format:username)
print(entrynumber)
if entrynumber = 1 then
closedmouth transparency 1
openmouth transparency 0
but I did not get past if entrynumber = 1, because it results in an error. "expected then, got '='"
Is there a way to set it up like this? the transparency thing is probably wrong, but I know how to do that. It works as far as printing the number.
I wish you luck
Thank you!! I'll ping you
@median steeple Hey, so I finally got to do it and it's working properly!
However, every time I leave and enter, it gives me the sane number as the first time I entered, is there any way to make it reroll each time I walk in?
I think I may know the awnser, actually, just took me a moment of thinking