Question about a possible value system

Just a heads up I am VERY new to scripting, and I wanted to know this ahead of time before I sunk a bunch of time into learning to code just to find out my idea isn’t even possible.

I have a question about whether or not it would be possible to create and utilize a value system that is similar to Undertale’s “Fun Value” system. The “Fun Value” system in Undertale utilizes a randomly generated number that determines what easter eggs appear in-game and determines what events happen while you play the game. The only way to get a new random number is to start a new game.

Now I know that you can set a random NumberValue via script, but would it be possible to trigger certain events based off of what number you get? I’m particularly wanting to use this for a single-player horror game that has similar gameplay mechanics to DDLC. I wanted to use a value system to determine whether or not you see certain images, dialog, and whether or not your GUI changes at certain points in the game. For example I have a fake mouse cursor setup using a GUI that follows your real mouse around. And it would be cool if I could have a script that checks what value you have, and if it matches the value the script is looking for, it will change the GUI cursor image and GUI cursor size for a short period of time and then switch it back to normal. (I already have a GUI mouse cursor setup so I can change certain aspects that you couldn’t with the real cursor, like the position of the GUI mouse cursor.)

If anything like this is possible, what exactly would I have to learn to pull this off? And if I didn’t explain something very well please let me know, I’m not the best at explaining things. Especially ideas.

Also I hope I put this in the right category…

3 Likes

You can use a generated number as the seed for a random generator (or just use the random generator without seed) to produce random numbers.

If you do Random:NextNumber() then you can use it to select something by probability. Say you want a 60% chance of something occurring,

local rand = Random.new()
if rand:NextNumber() <= 0.6 then
    -- Do the 60% chance thing.
else
    -- Do the 40% chance thing.
end

If you have multiple modes and want to select one you could use the Random:NextInteger( min, max ) functionality. Let’s take the example of 5 modes:

local modes = { 'One', 'Two', 'Three', 'Four', 'Five' }

local selectedMode = modes[ rand:NextInteger( 1, #modes ) ]
print( selectedMode ) -- Will print a random mode each time the code runs.
2 Likes

It looks like you answered your own question in your post. Yes, setting the value randomly then reading it and comparing it to different cases is exactly how you would do it. Assuming you know about generating random numbers since you mentioned it in your post, there isn’t anything else you need to know. As far as implementation goes that’s up to you and depends on your needs (for instance using an IntValue to share the value across multiple scripts).

1 Like

Thank you for the speedy reply and thank you for the information! Very much appreciated!

1 Like

Yes I do know about generating random numbers. And one of the things I did want to know was how to share the value across scripts. Thank you for the reply!

As far as sharing information across scripts goes, you can use objects or ModuleScripts depending on your case. One of the benefits of using a ModuleScript would be that you can implement some behavior on it and share it across scripts but they’re also commonly used to store large tables of data.

Alright cool, thank you for the information! This will help me out a lot!