#Change decal when receiving random number

28 messages · Page 1 of 1 (latest)

worthy vapor
#

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!

median steeple
#

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.

soft hare
# worthy vapor I'm a little stumped on how to do this, so maybe you all can help? I have a zone...

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.
median steeple
#

Almost correct

soft hare
#

Wdym?

soft hare
#

Yes, i dont know what the property of decals are called

#

So i took a guess

median steeple
#

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

median steeple
worthy vapor
#

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?

teal meteorBOT
#

studio** You are now Level 4! **studio

median steeple
#

Did it work?

worthy vapor
#

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.

median steeple
#

==

#

When using if statements you use == not =

#

@worthy vapor

worthy vapor
#

OHHH ok

#

LET ME TRY THAT, it may be a few hours until I get to the computer

median steeple
#

I wish you luck

worthy vapor
#

Thank you!! I'll ping you

worthy vapor
#

@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