#How to use variables from 1 Script in other Scripts?

1 messages · Page 1 of 1 (latest)

violet grove
#

I am trying to create Time in my game and i created working formula to count game time.

local TimeMultiple = 1
local TotalTime = 0
local Minutes = 0
local Hours = 0
local Days = 0
local Months = 0
local Years = 0

while true do
    TotalTime = TotalTime + 1 * TimeMultiple
    Minutes = Minutes + 1 * TimeMultiple
    if Minutes >= 60 then
        Hours = Hours + math.floor(Minutes / 60)
        Minutes = Minutes % 60
    end
    if Hours >= 24 then
        Days = Days + math.floor(Hours / 24)
        Hours = Hours % 24
    end
    if Days >= 30 then
        Months = Months + math.floor(Days / 30)
        Days = Days % 30
    end
    if Months >= 12 then
        Years = Years + math.floor(Months / 12)
        Months = Months % 12
    end
    task.wait(1)
end

How do i use Variables like "Hours" "Minutes" and etc in other scripts? I need to dispay time into UI Label and i want to add admin command ;time (number) to change TimeMultiple to change time speed for testing and etc. But when i tried do these with AI it died on creating Admin Chat command, AI can help me display time into label text, but he do these kinda weird and i don't understand few things how he do that, so i trying do these for my self, but i am very new to scripting so i don't know how to create Variable which i can use in other scripts. I already searched in internet about that, i found something like "module scripts" and when i tryed to use recieve thing it give an error and says "script must return 1 of something" and i have 7 variables to return, so i have no idea how to solve these problem. Help me out please.

storm wasp
#

you can use module scripts

#

or use like numvalues

violet grove
violet grove
storm wasp
#

ok

#

you can add it to whatever and just set the variable to

#

local hours = script.NumerValue

#

or soemthing

#

and when you want to change it or access the value you can do hours.Value += 1 or something

violet grove
#

what about my first message?

storm wasp
#

u gotta do local module = require(modulescript)

#

then in the actual module script do like module.hours = 0

#

then in the other script you can do module.hours += 1 or something

#

and it will change for all other scripts that required the module

violet grove
storm wasp
#

uhh idk

#

idk what shared is

#

wait i think they just named the module as shared

violet grove
#

i think yes, cuz module.variable = 1 give an error in syntax

#

ok thx i will try that solutions tommorrow