generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: Passing Variables?

Previous Thread :: Next Thread 
ThePixel is not online. 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
swimguy777 is not online. swimguy777
Joined: 30 May 2009
Total Posts: 17092
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 is not online. 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 is not online. 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 is not online. 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 is not online. 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 is not online. 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 is not online. 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
swimguy777 is not online. swimguy777
Joined: 30 May 2009
Total Posts: 17092
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 is not online. 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
swimguy777 is not online. swimguy777
Joined: 30 May 2009
Total Posts: 17092
25 Oct 2011 03:58 PM
...

Crap. Missed that bit.

-[::ƧѡÎḾḠΰῩ::]-
-[::Maker of stuff and Helper of Scripting::]-
Report Abuse
Robertoman is not online. Robertoman
Joined: 10 May 2007
Total Posts: 6369
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 is not online. 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
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image