LuckyAura
|
  |
| Joined: 25 Jul 2009 |
| Total Posts: 4444 |
|
|
| 10 Nov 2014 07:27 PM |
I have these tools that have a script in them which grabs the GUI from ReplicatedStorage, which works fine. The GUI shows up. But some of the things in the GUI don't work, and others do. It's driving me crazy. Can someone help me? Is there another place I can store GUI's where they will work if a copy is made??
Here's the script that calls for the GUI from ReplicatedStorage:
function LoadGui() repeat wait() until game.Players.LocalPlayer.Character if not gui then gui = game.ReplicatedStorage.YoungBenGUI:Clone() gui.Parent = game.Players.LocalPlayer.PlayerGui print("Gui placed into player.") else return end end
function UnloadGui() gui:Destroy() gui=nil end
script.Parent.Equipped:connect(function() LoadGui() end)
script.Parent.Unequipped:connect(function() UnloadGui() end)
These are two of the scripts inside of the GUI if it helps:
page = script.Parent.Page function close() script.Parent.C1.Visible = false end
function onChanged() if script.Parent['C'..page.Value] then close() script.Parent['C'..page.Value].Visible = true else return end end
page.Changed:connect(onChanged)
and
for i,c in pairs(script.Parent:GetChildren()) do if c:IsA("ImageButton") then c.MouseButton1Click:connect(function() p = script.Parent.Parent.Parent.Parent.Parent wait(0.25) for _,v in pairs(p.Character:GetChildren()) do if v:IsA("Tool") and v.Name~='YoungBensOmnitrix' then v:Destroy() end end for _,v in pairs(game.ServerStorage.GameTools[c.Suit.Tool.Value]:GetChildren()) do if v:IsA("HopperBin") or v:IsA("Tool") then if p:FindFirstChild'Backpack' then v:clone().Parent = p.Backpack end end end end) end end
Someone please help! |
|
|
| Report Abuse |
|
|
LuckyAura
|
  |
| Joined: 25 Jul 2009 |
| Total Posts: 4444 |
|
| |
|
|
| 10 Nov 2014 10:15 PM |
function LoadGui() repeat wait() until game.Players.LocalPlayer.Character if not gui then -- Why is this here? gui = game.ReplicatedStorage.YoungBenGUI:Clone() gui.Parent = game.Players.LocalPlayer.PlayerGui print("Gui placed into player.") else return end end
Why is there an if statement for gui if you have not defined the gui yet? You also have an else statement which returns nothing. Which breaks the loop you have going on in the first place. gui is already nil so you are basically waiting for gui to be true but you have not defined it yet!! |
|
|
| Report Abuse |
|
|
LuckyAura
|
  |
| Joined: 25 Jul 2009 |
| Total Posts: 4444 |
|
| |
|
Ojia
|
  |
| Joined: 08 Feb 2012 |
| Total Posts: 650 |
|
|
| 10 Nov 2014 11:42 PM |
| For stuff you want to use later in the script, such as 'gui', you'd put a local before it. |
|
|
| Report Abuse |
|
|
LuckyAura
|
  |
| Joined: 25 Jul 2009 |
| Total Posts: 4444 |
|
| |
|
LuckyAura
|
  |
| Joined: 25 Jul 2009 |
| Total Posts: 4444 |
|
| |
|
|
| 11 Nov 2014 10:30 AM |
| Replicated storage is only used by local scripts, not server side scripts, use ServerStorage instead. |
|
|
| Report Abuse |
|
|
LuckyAura
|
  |
| Joined: 25 Jul 2009 |
| Total Posts: 4444 |
|
|
| 11 Nov 2014 11:58 AM |
What do I change in the script so it takes it from ServerStorage?
function LoadGui() repeat wait() until game.Players.LocalPlayer.Character if not gui then gui = game.ServerStorage.YoungBenGUI:Clone() gui.Parent = game.Players.LocalPlayer.PlayerGui print("Gui placed into player.") else return end end
function UnloadGui() gui:Destroy() gui=nil end
script.Parent.Equipped:connect(function() LoadGui() end)
script.Parent.Unequipped:connect(function() UnloadGui() end) |
|
|
| Report Abuse |
|
|
LuckyAura
|
  |
| Joined: 25 Jul 2009 |
| Total Posts: 4444 |
|
|
| 11 Nov 2014 11:58 AM |
What do I change in the script so it takes it from ServerStorage? I get an error on line 3 and 14.
function LoadGui() repeat wait() until game.Players.LocalPlayer.Character if not gui then <-- gui = game.ServerStorage.YoungBenGUI:Clone() gui.Parent = game.Players.LocalPlayer.PlayerGui print("Gui placed into player.") else return end end
function UnloadGui() gui:Destroy() gui=nil end
script.Parent.Equipped:connect(function() LoadGui() <-- end)
script.Parent.Unequipped:connect(function() UnloadGui() end) |
|
|
| Report Abuse |
|
|
|
| 11 Nov 2014 11:59 AM |
| You got it, now just put the item in ServerStorage so it can get it |
|
|
| Report Abuse |
|
|
LuckyAura
|
  |
| Joined: 25 Jul 2009 |
| Total Posts: 4444 |
|
|
| 11 Nov 2014 12:04 PM |
Didn't mean to post twice..
I have both the tool and GUI in ServerStorage and it isn't working when I play.
In Studio, it works, but it gives me 7 copies of the GUI and it doesn't close after I press a button.
In play mode, doesn't work at all. Errors on Line 3 - global LoadGui and Line 14. |
|
|
| Report Abuse |
|
|
|
| 11 Nov 2014 12:14 PM |
| it doesnt look like gui is defined as a variable |
|
|
| Report Abuse |
|
|
LuckyAura
|
  |
| Joined: 25 Jul 2009 |
| Total Posts: 4444 |
|
|
| 11 Nov 2014 12:20 PM |
| But how do I fix it? I don't know much about scripting. |
|
|
| Report Abuse |
|
|
LuckyAura
|
  |
| Joined: 25 Jul 2009 |
| Total Posts: 4444 |
|
| |
|
LuckyAura
|
  |
| Joined: 25 Jul 2009 |
| Total Posts: 4444 |
|
| |
|
|
| 11 Nov 2014 01:30 PM |
local gui = [INSERT GUI HERE]
function LoadGui() repeat wait() until game.Players.LocalPlayer.Character if not gui then ...etc |
|
|
| Report Abuse |
|
|
LuckyAura
|
  |
| Joined: 25 Jul 2009 |
| Total Posts: 4444 |
|
|
| 11 Nov 2014 01:57 PM |
Here are errors from in game:
local gui = BenGUI
function LoadGui() repeat wait() until game.Players.LocalPlayer.Character if not gui then gui = game.ReplicatedStorage.BenGUI:Clone() <-Error: global UnloadGui gui.Parent = game.Players.LocalPlayer.PlayerGui print("Gui placed into player.") else return end end
function UnloadGui() gui:Destroy() <-- Error: global UnloadGui gui=nil end
script.Parent.Equipped:connect(function() LoadGui() <-- Error end)
script.Parent.Unequipped:connect(function() UnloadGui() <-- Error end) |
|
|
| Report Abuse |
|
|
|
| 11 Nov 2014 02:02 PM |
local player=game.Players.LocalPlayer local gui=player.PlayerGui.BenGUI
function LoadGui() repeat wait() until game.Players.LocalPlayer.Character if not gui then gui = game.ReplicatedStorage.BenGUI:Clone() <-Error: global UnloadGui gui.Parent = game.Players.LocalPlayer.PlayerGui print("Gui placed into player.") else return end end
function UnloadGui() gui:Destroy() <-- Error: global UnloadGui gui=nil end
script.Parent.Equipped:connect(function() LoadGui() <-- Error end)
script.Parent.Unequipped:connect(function() UnloadGui() <-- Error end) |
|
|
| Report Abuse |
|
|
|
| 11 Nov 2014 02:20 PM |
local gui = game.ReplicatedStorage:WaitForChild("BenGUI") -- this removes the need for the if statement
local Player = game.Players.LocalPlayer local Character = Player.CharacterAdded:wait() -- No longer need that repeat loop
function LoadGui() newGui = gui:Clone() -- Clone it newGui.Parent = Player.PlayerGui print("Gui placed into player.") end
function UnloadGui() gui:Destroy() -- removed gui = nil because it not needed end
script.Parent.Equipped:connect(LoadGui) -- You don't need to create a new function to call a function
script.Parent.Unequipped:connect(UnloadGui) -- You don't need to create a new function to call a function |
|
|
| Report Abuse |
|
|
LuckyAura
|
  |
| Joined: 25 Jul 2009 |
| Total Posts: 4444 |
|
|
| 11 Nov 2014 02:30 PM |
| @ShadowOfCrimson @darkemosoul Both of those don't load the GUI in either Studio or Play mode and no errors in either Developer Console or Output. |
|
|
| Report Abuse |
|
|
vacharya
|
  |
| Joined: 06 Jan 2011 |
| Total Posts: 511 |
|
|
| 11 Nov 2014 02:33 PM |
When I try doing something with GUI's I use _G.label = script.Parent then refrence it like y = _G.label:clone() y.Parent = game.Players.LocalPlayer.PlayerGui
:) idk i tried to help |
|
|
| Report Abuse |
|
|
|
| 11 Nov 2014 02:35 PM |
local gui = game.ServerStorage:WaitForChild("BenGUI") local Player = game.Players.LocalPlayer local Character = Player.CharacterAdded:wait()
script.Parent.Equipped:connect(function() newGui = gui:Clone() newGui.Parent = Player.PlayerGui print("Gui placed into player.") end)
script.Parent.Unequipped:connect(function() gui:Destroy() end)
--just be sure to put BenGUI in ServerStorage |
|
|
| Report Abuse |
|
|
LuckyAura
|
  |
| Joined: 25 Jul 2009 |
| Total Posts: 4444 |
|
|
| 11 Nov 2014 02:48 PM |
local gui = game.ServerStorage:WaitForChild("BenGUI") local Player = game.Players.LocalPlayer
script.Parent.Equipped:connect(function() newGui = gui:Clone() newGui.Parent = Player.PlayerGui print("Gui placed into player.") end)
script.Parent.Unequipped:connect(function() gui:Destroy() end)
Loads GUI in Studio, no errors. Doesn't load in play mode, error on line 1. |
|
|
| Report Abuse |
|
|
|
| 11 Nov 2014 02:54 PM |
*Scratches head* I thought you couldn't reach that service... In game... Or am I wrong? |
|
|
| Report Abuse |
|
|