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 » Scripting Helpers
Home Search
 

Re: Replacing old LocalScript with new LocalScript?

Previous Thread :: Next Thread 
monkey1589 is not online. monkey1589
Joined: 06 Feb 2010
Total Posts: 2334
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
Duelingwarlord is not online. Duelingwarlord
Joined: 15 Feb 2010
Total Posts: 22333
20 Jun 2014 10:02 PM
"game.Players.Name"

game.Players[name]
Report Abuse
swimguy777 is not online. swimguy777
Joined: 30 May 2009
Total Posts: 17092
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
Duelingwarlord is not online. Duelingwarlord
Joined: 15 Feb 2010
Total Posts: 22333
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
monkey1589 is not online. monkey1589
Joined: 06 Feb 2010
Total Posts: 2334
20 Jun 2014 10:05 PM
@swim That line finds the class (LocalScript) and attempts to remove it.
Report Abuse
swimguy777 is not online. swimguy777
Joined: 30 May 2009
Total Posts: 17092
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
monkey1589 is not online. monkey1589
Joined: 06 Feb 2010
Total Posts: 2334
20 Jun 2014 10:08 PM
I'm still getting that same error by Output
Report Abuse
monkey1589 is not online. monkey1589
Joined: 06 Feb 2010
Total Posts: 2334
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
swimguy777 is not online. swimguy777
Joined: 30 May 2009
Total Posts: 17092
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
Duelingwarlord is not online. Duelingwarlord
Joined: 15 Feb 2010
Total Posts: 22333
20 Jun 2014 10:19 PM
use :WaitForChild("PlayerGui")
Report Abuse
Duelingwarlord is not online. Duelingwarlord
Joined: 15 Feb 2010
Total Posts: 22333
20 Jun 2014 10:19 PM
line 14:

"game.Player"

game.Players*********
Report Abuse
monkey1589 is not online. monkey1589
Joined: 06 Feb 2010
Total Posts: 2334
20 Jun 2014 10:25 PM
@dueling I know, I saw your earlier post, I fixed it.
Report Abuse
monkey1589 is not online. monkey1589
Joined: 06 Feb 2010
Total Posts: 2334
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
Duelingwarlord is not online. Duelingwarlord
Joined: 15 Feb 2010
Total Posts: 22333
20 Jun 2014 10:28 PM
"new.Parent = game.Players.Name.PlayerGui.Battery.Frame"

new.Parent = game.Players[name].PlayerGui.Battery.Frame
Report Abuse
monkey1589 is not online. monkey1589
Joined: 06 Feb 2010
Total Posts: 2334
20 Jun 2014 10:29 PM
It finally worked, Thanks duel!
Report Abuse
monkey1589 is not online. monkey1589
Joined: 06 Feb 2010
Total Posts: 2334
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
Duelingwarlord is not online. Duelingwarlord
Joined: 15 Feb 2010
Total Posts: 22333
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
monkey1589 is not online. monkey1589
Joined: 06 Feb 2010
Total Posts: 2334
20 Jun 2014 11:05 PM
Is roblox broken? It didn't work!
Report Abuse
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
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
Duelingwarlord is not online. Duelingwarlord
Joined: 15 Feb 2010
Total Posts: 22333
20 Jun 2014 11:14 PM
"if old then"

that will break your script, old is never defined.
Report Abuse
monkey1589 is not online. monkey1589
Joined: 06 Feb 2010
Total Posts: 2334
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
monkey1589 is not online. monkey1589
Joined: 06 Feb 2010
Total Posts: 2334
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
Duelingwarlord is not online. Duelingwarlord
Joined: 15 Feb 2010
Total Posts: 22333
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
monkey1589 is not online. monkey1589
Joined: 06 Feb 2010
Total Posts: 2334
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
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
20 Jun 2014 11:23 PM
Are you sure that the LocalScript is in that part of the GUI?
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • 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