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 » Scripters
Home Search
 

Re: This problem is hounting me for ages...

Previous Thread :: Next Thread 
loleris is not online. loleris
Joined: 23 Feb 2009
Total Posts: 1610
12 Jul 2012 12:54 PM
the local script glitch...
At some point, weapon scripts that are localscripts (It must be local script)
just wont function properlly. On solo mode it does, but when online it doesnt.
Sometimes putting "wait(0.3)" in the beginning helps, but now It doesn't.
I need help.
Report Abuse
su8 is not online. su8
Joined: 06 Mar 2009
Total Posts: 6334
12 Jul 2012 01:00 PM
It means the localscript starts running before it can even access the objects received from the server, like workspace and such.
Report Abuse
loleris is not online. loleris
Joined: 23 Feb 2009
Total Posts: 1610
12 Jul 2012 01:01 PM
Well how do i get to know the server acces is ready?
Report Abuse
Candymaniac is not online. Candymaniac
Joined: 08 Oct 2009
Total Posts: 8985
12 Jul 2012 01:04 PM
Just put wait(1) or something at the first line so it waits...

☜▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬☜☆☞▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬☞ - Candymaniac, a highly reactive substance.
Report Abuse
loleris is not online. loleris
Joined: 23 Feb 2009
Total Posts: 1610
12 Jul 2012 01:13 PM
Did that, still not working.
Report Abuse
stravant is not online. stravant
Forum Moderator
Joined: 22 Oct 2007
Total Posts: 2893
12 Jul 2012 01:18 PM
Do something like this. For instance, if you need a value "Ammo" in the tool:

while not Tool:FindFirstChild('Ammo') do Tool.ChildAdded:wait() end

Which will pause the script until the Ammo value exists on the client.
Report Abuse
Combrad is not online. Combrad
Joined: 18 Jul 2009
Total Posts: 11025
12 Jul 2012 01:24 PM
Adding on to Stravant's ROBLOX uses a method much like that.

function WaitForChild(ChildName,Parent)
while not Parent:FindFirstChild(ChildName) do Parent.ChildAdded:wait() end
return Parent[ChildName]
end

Then you can declare the variables like so.

local AmmoValue = WaitForChild("Ammo",Tool)
local ShootSound = WaitForChild("Shoot1",Tool.Handle)

Something like that :D
Report Abuse
loleris is not online. loleris
Joined: 23 Feb 2009
Total Posts: 1610
12 Jul 2012 01:28 PM
thanks, that might do it... lot's of editing up ahead...
Report Abuse
BenBonez is not online. BenBonez
Joined: 29 Aug 2008
Total Posts: 19362
12 Jul 2012 02:03 PM
here is ROBLOX's entire function:

local function waitForChild(parent, childName)
local child = parent:findFirstChild(childName)
if child then return child end
while true do
child = parent.ChildAdded:wait()
if child.Name==childName then return child end
end
end
Report Abuse
Combrad is not online. Combrad
Joined: 18 Jul 2009
Total Posts: 11025
12 Jul 2012 02:04 PM
Prefer XLego's method.
Report Abuse
JulienDethurens is not online. JulienDethurens
Joined: 11 Jun 2009
Total Posts: 11046
12 Jul 2012 03:58 PM
Better:

while not parent.ChildAdded:wait().Name == "Child" do end

Even better:

repeat until parent.ChildAdded:wait().Name == "Child"

'parent' is the parent, "Child" is the name of the child.
Report Abuse
stravant is not online. stravant
Forum Moderator
Joined: 22 Oct 2007
Total Posts: 2893
12 Jul 2012 04:15 PM
repeat until parent.ChildAdded:wait().Name == "Child"

That is actually my favorite Lua gem. I use it all the time similarly to wait for animations to finish:

repeat until anim.KeyframeReached:wait() == 'CompleteFrameName'
Report Abuse
ColorfulBody is not online. ColorfulBody
Joined: 17 Jun 2012
Total Posts: 2353
12 Jul 2012 04:18 PM
And you can do this too:

repeat until object.Changed:wait() == "Name"

It will wait until an object's Name property changes.

In fact, you can even wait until an object with a certain class is added to a certain object:

repeat until parent.ChildAdded:wait():IsA('BasePart')
Report Abuse
HotThoth is not online. HotThoth
Forum Moderator
Joined: 24 Aug 2010
Total Posts: 1176
12 Jul 2012 07:45 PM
To be totally safe, I would prefer something more like the original one but with nil checks, since you don't want your WaitForChild function to ever break (if Parent is nil, it will crash).

function WaitForChild(parent, child)
if not parent then return end
while not parent:FindFirstChild(child) do parent.ChildAdded:wait() end
end
Report Abuse
Combrad is not online. Combrad
Joined: 18 Jul 2009
Total Posts: 11025
13 Jul 2012 07:42 AM
I always like to make it return the child, then you can use it within variables.
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • 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