I am quite new to roblox scripting, I'm experienced with A similar language (Zero) in the past but don't know what to do here
This script is making a time variable for the entire scripts
time = 0 -- A time Variable for throughout the entire Workspace while true do -- True boolean to repeat it all time = time + 1 -- add 1 to the time wait(1) -- wait .9 seconds in order to not overload the script if time == 820 then -- Makes sure the round can't go longer than 12 minutes time = 0 -- sets the time Variable back to 0 end --ends the if statement print(time) --Prints "time" for debugging end -- ends the While true
this is one of the many places I'm using that script
playerNames = game.Players:GetChildren() --Find the names of all the players function kill() -- Kill all players for i = 1, #playerNames do --repeat until all the players are killed game.Workspace[playerNames[i].Name].Humanoid.Health = 0 --kill the player end ----finished end -- Ends the kill() function while true do if time >= 90 then --Time for people to choose character kill() -- Runs the kill() function if time >= 820 then for i=1, #playerNames do playerNames[i].TeamColor = BrickColor.new("White") end --Ends the "for" statement kill() -- Runs the kill() function end --Ends this "if" statment end -- Ends the "if" statement end
You mean that you want one variable that is available in every script in your game, correct?
There's two ways you can do this that I know of.
Create an IntValue(Or NumberValue) in game.Workspace and set its value each time through the timer loop, then you can read that value in other scripts
Use _G, the global variable table. I don't know much about it, but there's more info here: http://wiki.roblox.com/index.php?title=Function_Dump/Core_Functions#G
If it's the same script then yes, just define it outside any scope or omit any local from it. However, if it is a different script you will need to use _G which is Lua's global table.
_G["time"] = 0
You can reference to it by:
if _G["time"] > 1 then end
Read more about it here
@ipiano, I dont think he wants it global. He only wants it local i believe so do.
local time = 0
Explaination. putting local infront of time makes it a script value. but _G would make that value usuable thru every script.