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
|
  |
| 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
|
  |
| 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 |
|
|
|
| 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
|
  |
| Joined: 23 Feb 2009 |
| Total Posts: 1610 |
|
|
| 12 Jul 2012 01:13 PM |
| Did that, still not working. |
|
|
| Report Abuse |
|
|
stravant
|
  |
 |
| 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
|
  |
| 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
|
  |
| 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
|
  |
| 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
|
  |
| Joined: 18 Jul 2009 |
| Total Posts: 11025 |
|
| |
|
|
| 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
|
  |
 |
| 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 |
|
|
|
| 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
|
  |
 |
| 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
|
  |
| 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 |
|
|