|
| 31 Mar 2012 02:21 PM |
I'm working on an interactive dialog system with GUIs, and I have a script in an NPC's torso that detects the magnitude of players' torsos and does stoof accordingly. Everything works fine ingame, until about after 5 minutes, when the script suddenly breaks for no apparent reason. I've used a few scripts using magnitude for doors etc. before, and this would always happen. Is there any way to fix this?
Here's my script.
while wait() do p = game.Players:GetChildren() for i=1, #p do if (p[i].Character.Torso.Position - script.Parent.Position).magnitude <= 5 then if p[i].PlayerGui:FindFirstChild("Interact") == nil then local igui = script.Parent.Interact:Clone() igui.Parent = p[i].PlayerGui igui.Main.Owner.Value = script.Parent igui.Main.Enter.Disabled = false igui.Main.Leave.Disabled = false end else wait() end end end
|
|
|
| Report Abuse |
|
|
| |
|
|
| 31 Mar 2012 02:34 PM |
| Maybe it is breaking because the Torso can't be found? |
|
|
| Report Abuse |
|
|
|
| 31 Mar 2012 02:38 PM |
I don't think so, but I'll try that.
Got a siggy :D ○ Interpret that any way you want. ○ |
|
|
| Report Abuse |
|
|
|
| 31 Mar 2012 02:40 PM |
| Sometimes, players' characters are nil, which means you can't index 'Torso' from the character. Either check to see if the player has a character, or you can surround the entire thing with pcall. |
|
|
| Report Abuse |
|
|
|
| 31 Mar 2012 02:45 PM |
Ah, good idea. Thanks, Firefox.
○ Interpret that any way you want. ○ |
|
|
| Report Abuse |
|
|