Is there any way to reference a variable from a different script?

I’ve got a variable for a stopwatch system for the time and I want to put the time in a “you completed the level in (time)” but I can’t find a good way of doing it without the variable thats in a different script.

1 Like

Do you mean that you have a variable representing the time in a different script but you can’t reference it from another script?

1 Like

In my GUI script, I’m trying to change text in the UI and I have a variable in the actual stopwatch script.

1 Like

in your stopwatch script, if you have a variable like this:
local time = 0

then you can’t reference that variable from a different script unfortunately

if you want to have a value that you can reference across different scripts, you’ll have to create a NumberValue instance and then manipulate it through your scripts.

so instead of local time = 0, you can create the NumberValue, then reference it in your stopwatch script and then manipulate it instead of manipulating the old value.

and you can reference the NumberValue again from your gui script and get its value

also if you don’t mind, can i see the stopwatch script?

will attributes/modulescripts work for you?

image
late response, but this is what shows up.
my stopwatch script has a format like this 00:00.00