ThePixel
|
  |
| Joined: 15 May 2010 |
| Total Posts: 225 |
|
|
| 25 Oct 2011 03:30 PM |
| Is it possible to declare a variable in one script, the use it in another? I want to declare how many players were in the game at a certain point in one script, then the button which has a different script (It's a ontouched), will need to use that variable. |
|
|
| Report Abuse |
|
|
|
| 25 Oct 2011 03:32 PM |
Script 1:
_G.moo = "HAI"
All other scripts:
print(_G.moo)
Output: HAI
-[::ƧѡÎḾḠΰῩ::]- -[::Maker of stuff and Helper of Scripting::]- |
|
|
| Report Abuse |
|
|
ThePixel
|
  |
| Joined: 15 May 2010 |
| Total Posts: 225 |
|
|
| 25 Oct 2011 03:34 PM |
_G.numplayers = #game.Players:GetPlayers()
So that will store the current number of players in a global variable? |
|
|
| Report Abuse |
|
|
nate890
|
  |
| Joined: 22 Nov 2008 |
| Total Posts: 21686 |
|
|
| 25 Oct 2011 03:35 PM |
| ^Yes, at the current time the code is ran, that will be the number of players at that time. |
|
|
| Report Abuse |
|
|
ThePixel
|
  |
| Joined: 15 May 2010 |
| Total Posts: 225 |
|
|
| 25 Oct 2011 03:43 PM |
While I'm here I'll ask another question.
How would I get the script to check if the player who hit it has a bool value with a certain name in there character, if they do it will end and if they don't it will give them a bool value with a certain name. |
|
|
| Report Abuse |
|
|
nate890
|
  |
| Joined: 22 Nov 2008 |
| Total Posts: 21686 |
|
|
| 25 Oct 2011 03:46 PM |
"who hit it" What? "if they do it will end" Waat? "give them a bool value with a certain name." Certain name?
"How would I get the script to check if the player who hit it has a bool value with a certain name in there character, if they do it will end and if they don't it will give them a bool value with a certain name"
Please rewrite that. |
|
|
| Report Abuse |
|
|
ThePixel
|
  |
| Joined: 15 May 2010 |
| Total Posts: 225 |
|
|
| 25 Oct 2011 03:49 PM |
| Long story short, I'm trying to make a button where if you hit it, it checks if you've already hit it before. If you have, if simply does nothing but if it's your first time it runs the code. |
|
|
| Report Abuse |
|
|
nate890
|
  |
| Joined: 22 Nov 2008 |
| Total Posts: 21686 |
|
|
| 25 Oct 2011 03:52 PM |
THANKS;
script.Parent.Touched:connect(function(hit) if game.Players:GetPlayerFromCharacter(hit.Parent) then plyr=game.Players:GetPlayerFromCharacter(hit.Parent) if plyr:FindFirstChild("Valueee") then print("This player has touched dis before") else hasTouched=Instance.new("BoolValue",plyr) hasTouched.Name="Valueee" end end end) |
|
|
| Report Abuse |
|
|
|
| 25 Oct 2011 03:53 PM |
Something like this?
alreadyHit = {}
script.Parent.Touched:connect(function(hit) if game.Players:GetPlayerFromCharacter(hit.Parent) then for i,v in pairs(alreadyHit) do if hit.Parent.Name == v then --DON'T LET IN else --LET IN end end end end) -[::ƧѡÎḾḠΰῩ::]- -[::Maker of stuff and Helper of Scripting::]- |
|
|
| Report Abuse |
|
|
nate890
|
  |
| Joined: 22 Nov 2008 |
| Total Posts: 21686 |
|
|
| 25 Oct 2011 03:55 PM |
table.insert(alreadyHit,hit.Parent.Name) --LET IN end end end end)
|
|
|
| Report Abuse |
|
|
|
| 25 Oct 2011 03:58 PM |
...
Crap. Missed that bit.
-[::ƧѡÎḾḠΰῩ::]- -[::Maker of stuff and Helper of Scripting::]- |
|
|
| Report Abuse |
|
|
|
| 25 Oct 2011 04:19 PM |
OBJECTNAME="???" script.Parent.Touched:connect(function(h)if not h.Parent:FindFirstChild(OBJECTNAME)then Instance.new('BoolValue',h.Parent).Name=OBJECTNAME end end) |
|
|
| Report Abuse |
|
|
Legend26
|
  |
| Joined: 08 Sep 2008 |
| Total Posts: 10586 |
|
|
| 25 Oct 2011 04:23 PM |
I'd like to extend on swimguy's first post.
While in normal Lua, you would always use '_G' for global variables, in Roblox there is another global table provided called 'shared' which is used the exact same way. |
|
|
| Report Abuse |
|
|