Shokwav
|
  |
| Joined: 16 Aug 2008 |
| Total Posts: 9263 |
|
|
| 24 Jul 2013 01:53 AM |
| I recently had this issue with a few LocalScripts. They would function very strangely, and would simply pass through my script without really doing anything. I tried adding WaitForChild on every single thing I was accessing, still no dice. Finally I added an empty wait() at the top of my script, and like magic it was working! I was assumig it was some latency between the scripts actually running and when the objects were injected, but like I said, that didn't seem to be the issue. Anyone know anything about this? |
|
|
| Report Abuse |
|
|
|
| 24 Jul 2013 02:15 AM |
| All hail the almighty wait. |
|
|
| Report Abuse |
|
|
loleris
|
  |
| Joined: 23 Feb 2009 |
| Total Posts: 1610 |
|
|
| 24 Jul 2013 02:40 AM |
Same problem OP... Same problem... But I know a solution for a repeated use of the same localscript. You see, if you load the same localscript again (like starterpack) after the player dies and respawns, you can stop waiting at the start of the script. The script source has to "load". I only know that it really works:
--Script start if G_.ThisScriptHasLoaded == nil then wait(2) G_.ThisScriptHasLoaded = true end --Script source below
There's no other solution known to me. |
|
|
| Report Abuse |
|
|
Shokwav
|
  |
| Joined: 16 Aug 2008 |
| Total Posts: 9263 |
|
|
| 24 Jul 2013 02:47 AM |
| Oh wow, that was exactly what was happening- I had the script in the StarterPack, and it wasn't behaving properly after a character reloaded. Thanks for that! |
|
|
| Report Abuse |
|
|
| |
|
Oysi
|
  |
| Joined: 06 Jul 2009 |
| Total Posts: 9058 |
|
| |
|
Shokwav
|
  |
| Joined: 16 Aug 2008 |
| Total Posts: 9263 |
|
|
| 24 Jul 2013 01:06 PM |
| ^Does Lua not do integer division ._. |
|
|
| Report Abuse |
|
|
booing
|
  |
| Joined: 04 May 2009 |
| Total Posts: 6594 |
|
| |
|
Shokwav
|
  |
| Joined: 16 Aug 2008 |
| Total Posts: 9263 |
|
| |
|
|
| 24 Jul 2013 05:49 PM |
| wait(1/30) is nearly the same as wait(). |
|
|
| Report Abuse |
|
|
Shokwav
|
  |
| Joined: 16 Aug 2008 |
| Total Posts: 9263 |
|
|
| 24 Jul 2013 05:50 PM |
| I know that. I'm saying that normally 1/30 is integer division |
|
|
| Report Abuse |
|
|
NVI
|
  |
| Joined: 11 Jan 2009 |
| Total Posts: 4744 |
|
| |
|
Shokwav
|
  |
| Joined: 16 Aug 2008 |
| Total Posts: 9263 |
|
|
| 24 Jul 2013 07:24 PM |
| Oh. So does anyone know why that fixed it? It's a standalone script |
|
|
| Report Abuse |
|
|
blocco
|
  |
| Joined: 14 Aug 2008 |
| Total Posts: 29474 |
|
|
| 24 Jul 2013 08:00 PM |
| LocalScripts- code in general just doesn't stop working. I'm calling shenanigans. There's got to be a deeper issue. |
|
|
| Report Abuse |
|
|
Shokwav
|
  |
| Joined: 16 Aug 2008 |
| Total Posts: 9263 |
|
|
| 24 Jul 2013 09:08 PM |
Take a look. In StarterPack, only works on the first life without the wait().
wait(); -----constants----- local MAX_WHEEL_VALUE = 5; local MIN_WHEEL_VALUE = 0; local DEFAULT_WHEEL_DEADZONE = 3;
-----globals----- --player/character local plyr = script.Parent.Parent; plyr.Character:WaitForChild("Torso");
local char = plyr.Character;
--camera local plyr_cam = workspace.CurrentCamera;
--mouse local mouse = plyr:GetMouse(); local wheel_val = 0; local wheel_dz = DEFAULT_WHEEL_DEADZONE; local dz_inc = 0;
--gameobjects local game_objs = game.Lighting.GameObjects; local local_sounds = game_objs.LocalSounds.LocalSoundPart:Clone();
if(plyr_cam:FindFirstChild("LocalSoundPart"))then plyr_cam.LocalSoundPart:Destroy(); end local part_weld = Instance.new("Weld", local_sounds); part_weld.Part0 = local_sounds; part_weld.Part1 = char.Torso; local_sounds.Parent = plyr_cam;
-----function declarations----- local UpdateWheelGUI = function() end
local EquipWheelWeapon = function() print(wheel_val); local_sounds.WheelSwitch:Play(); end
-----events----- mouse.Button1Down:connect(function() local pos = mouse.Hit; local targ = mouse.Target; end)
mouse.WheelForward:connect(function() if(dz_inc == wheel_dz)then if(wheel_val < MAX_WHEEL_VALUE)then wheel_val = wheel_val + 1; else wheel_val = MIN_WHEEL_VALUE; end EquipWheelWeapon(); dz_inc = 0; else dz_inc = dz_inc + 1; end end)
mouse.WheelBackward:connect(function() if(dz_inc == wheel_dz)then if(wheel_val > MIN_WHEEL_VALUE)then wheel_val = wheel_val - 1; else wheel_val = MAX_WHEEL_VALUE; end EquipWheelWeapon(); dz_inc = 0; else dz_inc = dz_inc + 1; end end)
-----main----- --lock cam plyr.CameraMode = Enum.CameraMode.Classic; plyr.CameraMode = Enum.CameraMode.LockFirstPerson; |
|
|
| Report Abuse |
|
|
blocco
|
  |
| Joined: 14 Aug 2008 |
| Total Posts: 29474 |
|
|
| 24 Jul 2013 09:14 PM |
| Instead of plyr = script.Parent.Parent, use plyr = game.Players.LocalPlayer. Guaranteed to work 100% of the time, unless you screwed up RobloxPlayerBeta.exe |
|
|
| Report Abuse |
|
|
Shokwav
|
  |
| Joined: 16 Aug 2008 |
| Total Posts: 9263 |
|
|
| 24 Jul 2013 09:20 PM |
| I just did that. Now it doesn't even work online, yet it works in the server test, where it's doing the same thing and not working after the first death. I am absolutely frustrated. |
|
|
| Report Abuse |
|
|
blocco
|
  |
| Joined: 14 Aug 2008 |
| Total Posts: 29474 |
|
|
| 24 Jul 2013 09:23 PM |
| Try using a WaitForChild on anything that the game might have to load. Like game.Lighting and descendants |
|
|
| Report Abuse |
|
|
Shokwav
|
  |
| Joined: 16 Aug 2008 |
| Total Posts: 9263 |
|
|
| 24 Jul 2013 09:30 PM |
I added this to the start:
game:WaitForChild("Lighting"); game.Lighting:WaitForChild("GameObjects"); game.Lighting.GameObjects:WaitForChild("LocalSounds"); game.Lighting.GameObjects.LocalSounds:WaitForChild("LocalSoundPart"); game.Lighting.GameObjects.LocalSounds.LocalSoundPart:WaitForChild("WheelSwitch");
Only works once. Utter insanity. |
|
|
| Report Abuse |
|
|
mew903
|
  |
| Joined: 03 Aug 2008 |
| Total Posts: 22071 |
|
|
| 24 Jul 2013 09:31 PM |
"wait(1/30) is nearly the same as wait()" Game:GetService('RunService').Stepped:wait() is closer because wait() can vary on how much lag you or the server has I believe |
|
|
| Report Abuse |
|
|
blocco
|
  |
| Joined: 14 Aug 2008 |
| Total Posts: 29474 |
|
|
| 24 Jul 2013 09:31 PM |
| You know that WaitForChild returns the object, right? |
|
|
| Report Abuse |
|
|
Shokwav
|
  |
| Joined: 16 Aug 2008 |
| Total Posts: 9263 |
|
|
| 24 Jul 2013 09:32 PM |
| I didn't know that. But that doesn't really help me |
|
|
| Report Abuse |
|
|
Shokwav
|
  |
| Joined: 16 Aug 2008 |
| Total Posts: 9263 |
|
|
| 24 Jul 2013 09:32 PM |
| Again, if I replace all of that with a wait() it works perfectly online. I KNOW all of those functions take longer than 1/30th of a second |
|
|
| Report Abuse |
|
|
dekkonot
|
  |
| Joined: 22 Dec 2010 |
| Total Posts: 6685 |
|
|
| 24 Jul 2013 09:58 PM |
wait() at the top of the script fixes 30% of all errors.
~ Linguam latinam est optimum ~ |
|
|
| Report Abuse |
|
|
Shokwav
|
  |
| Joined: 16 Aug 2008 |
| Total Posts: 9263 |
|
| |
|