|
| 20 Jun 2014 10:00 PM |
local db = false function onTouched(part) local h = part.Parent:findFirstChild("Humanoid") if h~=nil then if db == false then db = true local name = h.Parent.Name for _, child in ipairs(game.Players.Name.PlayerGui.Battery.Frame:GetChildren()) do if child.ClassName == 'LocalScript' then if old then child:Remove() end local new = script.Normal:Clone() new.Parent = game.Player.Name.PlayerGui.Battery.Frame new.Name = "Normal (10 Minutes)" new.Disabled = false script.Parent.Transparency = 1 script.Parent.Parent.Part2.Transparency = 1 wait(60) script.Parent.Transparency = 0 script.Parent.Parent.Part2.Transparency = 0 db = false end end end end end script.Parent.Touched:connect(onTouched)
What I want to do is when I touch the part, A LocalScript that is in my PlayerGui will get removed, and will be replaced with a new one. Output gives me this error when I touch the brick.
19:57:12.755 - Workspace.Battery.Part1.Script:8: attempt to index field 'PlayerGui' (a nil value) 19:57:12.757 - Stack Begin 19:57:12.758 - Script 'Workspace.Battery.Part1.Script', Line 8 19:57:12.759 - Stack End 19:57:12.760 - Disconnected event because of exception |
|
|
| Report Abuse |
|
|
|
| 20 Jun 2014 10:02 PM |
"game.Players.Name"
game.Players[name] |
|
|
| Report Abuse |
|
|
|
| 20 Jun 2014 10:03 PM |
I don't understand this line: for _, child in ipairs(game.Players.Name.PlayerGui.Battery.Frame:GetChildren()) do
What are you trying to make this line do?
-[::ƧѡÎḾḠΰῩ::]-[::Helper of Scripting and Writer of Wikis::] |
|
|
| Report Abuse |
|
|
|
| 20 Jun 2014 10:03 PM |
Learn to debug, in one line you use game.Player instead of game.Players.
Debug your code before you post here. |
|
|
| Report Abuse |
|
|
|
| 20 Jun 2014 10:05 PM |
| @swim That line finds the class (LocalScript) and attempts to remove it. |
|
|
| Report Abuse |
|
|
|
| 20 Jun 2014 10:07 PM |
I should probably try to understand the script before I point stuff out.
The other guy was right, replace that line with this: for _, child in ipairs(game.Players[name].PlayerGui.Battery.Frame:GetChildren()) do
-[::ƧѡÎḾḠΰῩ::]-[::Helper of Scripting and Writer of Wikis::] |
|
|
| Report Abuse |
|
|
|
| 20 Jun 2014 10:08 PM |
| I'm still getting that same error by Output |
|
|
| Report Abuse |
|
|
|
| 20 Jun 2014 10:09 PM |
I'm still getting that same error by Output. 20:07:26.821 - Workspace.Battery.Part1.Script:14: attempt to index field 'PlayerGui' (a nil value) 20:07:26.823 - Stack Begin 20:07:26.824 - Script 'Workspace.Battery.Part1.Script', Line 14 20:07:26.825 - Stack End 20:07:26.826 - Disconnected event because of exception |
|
|
| Report Abuse |
|
|
|
| 20 Jun 2014 10:18 PM |
Because you didn't change it to what I posted earlier
-[::ƧѡÎḾḠΰῩ::]-[::Helper of Scripting and Writer of Wikis::] |
|
|
| Report Abuse |
|
|
|
| 20 Jun 2014 10:19 PM |
| use :WaitForChild("PlayerGui") |
|
|
| Report Abuse |
|
|
|
| 20 Jun 2014 10:19 PM |
line 14:
"game.Player"
game.Players********* |
|
|
| Report Abuse |
|
|
|
| 20 Jun 2014 10:25 PM |
| @dueling I know, I saw your earlier post, I fixed it. |
|
|
| Report Abuse |
|
|
|
| 20 Jun 2014 10:27 PM |
Still same error, but in case if I placed it in the wrong place, I got the newer version of the script right here:
local db = false function onTouched(part) local h = part.Parent:findFirstChild("Humanoid") if h~=nil then if db == false then db = true local name = h.Parent.Name game.Players[name]:WaitForChild("PlayerGui") for _, child in ipairs(game.Players[name].PlayerGui.Battery.Frame:GetChildren()) do if child.ClassName == 'LocalScript' then if old then child:Remove() end local new = script.Normal:Clone() new.Parent = game.Players.Name.PlayerGui.Battery.Frame new.Name = "Normal (10 Minutes)" new.Disabled = false script.Parent.Transparency = 1 script.Parent.Parent.Part2.Transparency = 1 wait(60) script.Parent.Transparency = 0 script.Parent.Parent.Part2.Transparency = 0 db = false end end end end end script.Parent.Touched:connect(onTouched) |
|
|
| Report Abuse |
|
|
|
| 20 Jun 2014 10:28 PM |
"new.Parent = game.Players.Name.PlayerGui.Battery.Frame"
new.Parent = game.Players[name].PlayerGui.Battery.Frame |
|
|
| Report Abuse |
|
|
|
| 20 Jun 2014 10:29 PM |
| It finally worked, Thanks duel! |
|
|
| Report Abuse |
|
|
|
| 20 Jun 2014 10:54 PM |
We got a new problem. Even though the new localscript comes in, the old one will not be removed for some odd reason.
Lets focus only in this part of the code!
for _, child in ipairs(game.Players[name].PlayerGui.Battery.Frame:GetChildren()) do if child.ClassName == 'LocalScript' then child:Remove() end
Anyway to correct this? |
|
|
| Report Abuse |
|
|
|
| 20 Jun 2014 10:55 PM |
for _, child in pairs(game.Players[name].PlayerGui.Battery.Frame:GetChildren()) do if child:IsA('LocalScript') then child:Destroy() end |
|
|
| Report Abuse |
|
|
|
| 20 Jun 2014 11:05 PM |
| Is roblox broken? It didn't work! |
|
|
| Report Abuse |
|
|
|
| 20 Jun 2014 11:11 PM |
I know it's inefficient but have you tried forcing it?
for _,child in ipairs(game.Players[name].PlayerGui.Battery.Frame:GetChildren()) do if child:IsA("LocalScript") then repeat wait() child:Destroy() until child == nil end |
|
|
| Report Abuse |
|
|
|
| 20 Jun 2014 11:14 PM |
"if old then"
that will break your script, old is never defined. |
|
|
| Report Abuse |
|
|
|
| 20 Jun 2014 11:16 PM |
How about trying to wait for the script before it ready for it to be ready to removed?
game.Players[name].PlayerGui.Battery.Frame:WaitForChild(What do I type here?) |
|
|
| Report Abuse |
|
|
|
| 20 Jun 2014 11:16 PM |
| Oh yeah I noticed that when I was zooming in and removed it, but it doesn't work for some odd reason! |
|
|
| Report Abuse |
|
|
|
| 20 Jun 2014 11:18 PM |
| Can you post the ENTIRE script, although I am going offline I'll fix it for you(unless someone beats me to it) |
|
|
| Report Abuse |
|
|
|
| 20 Jun 2014 11:20 PM |
Newest part of the script: local db = false function onTouched(part) local h = part.Parent:findFirstChild("Humanoid") if h~=nil then if db == false then db = true local name = h.Parent.Name game.Players[name]:WaitForChild("PlayerGui") for _,child in ipairs(game.Players[name].PlayerGui.Battery.Frame:GetChildren()) do if child:IsA("LocalScript") then repeat wait() child:Destroy() until child == nil end
local new = script.Normal:Clone() new.Parent = game.Players[name].PlayerGui.Battery.Frame new.Name = "Normal (10 Minutes)" new.Disabled = false script.Parent.Transparency = 1 script.Parent.Parent.Part2.Transparency = 1 wait(60) script.Parent.Transparency = 0 script.Parent.Parent.Part2.Transparency = 0 db = false end end end end script.Parent.Touched:connect(onTouched) |
|
|
| Report Abuse |
|
|
|
| 20 Jun 2014 11:23 PM |
| Are you sure that the LocalScript is in that part of the GUI? |
|
|
| Report Abuse |
|
|