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: .Touched GUI Giver Only Works Once

Previous Thread :: Next Thread 
SockPuppetCow is not online. SockPuppetCow
Joined: 14 Sep 2012
Total Posts: 121
09 Jan 2013 08:08 PM
So I've got this GUI Giver thingy that gives you the GUI into your PlayerGui when you touch it. It's supposed to give it to you when you touch the brick, then take it away when you leave the brick. It does that just fine, but if you try to get the GUI again, it gives you a "Disconnected event because of exception" message in Output. Here's the script:

local Gui = script.AlarmBroadcastGui
local c = Gui:Clone()
script.Parent.Touched:connect(function(hit)
local char = hit.Parent
local player = game.Players:GetPlayerFromCharacter(char)
c.Parent = player.PlayerGui
end)
script.Parent.TouchEnded:connect(function(hit2)
local char2 = hit2.Parent
local player2 = game.Players:GetPlayerFromCharacter(char2)
local Gui2 = player2.PlayerGui:FindFirstChild("AlarmBroadcastGui")
if Gui2 ~= nil then
Gui2:Destroy()
end
end)
Report Abuse
noah is online. noah
Joined: 11 Sep 2006
Total Posts: 18977
09 Jan 2013 08:14 PM
local Gui = script.AlarmBroadcastGui
script.Parent.Touched:connect(function(hit)
human = hit.Parent:findFirstChild("Humanoid")
if human then
player = game.Players:GetPlayerFromCharacter(hit.Parent)
local c = Gui:Clone()
c.Parent = player.PlayerGui
elseif not human then
c:Destroy()
end
end)
Report Abuse
noah is online. noah
Joined: 11 Sep 2006
Total Posts: 18977
09 Jan 2013 08:16 PM
i no like using da touchended :x
Report Abuse
SockPuppetCow is not online. SockPuppetCow
Joined: 14 Sep 2012
Total Posts: 121
09 Jan 2013 08:28 PM
Problem though. It needs to remove the GUI when the brick is left. It's also in a thing to get weapons from a GUI. Except the Weapon GUI is this big thing in the middle of the screen. If it were just the alarm system it'd be fine. Thanks anyways.
Report Abuse
KnightmareXD is not online. KnightmareXD
Joined: 14 Jul 2009
Total Posts: 11189
09 Jan 2013 08:32 PM
    local Gui = script.AlarmBroadcastGui
    script.Parent.Touched:connect(function(hit)
    local char = hit.Parent
    local player = game.Players:GetPlayerFromCharacter(char)
    if not char or player then return end
    local c = Gui:Clone()
    c.Parent = player.PlayerGui
    end)
    
    script.Parent.TouchEnded:connect(function(hit2)
    local char2 = hit2.Parent
    local player2 = game.Players:GetPlayerFromCharacter(char2)
    local Gui2 = player2.PlayerGui:FindFirstChild("AlarmBroadcastGui")
    if Gui2 ~= nil then
    Gui2:Destroy()
    end
    end)

¤ ¤ † K M X D † ¤ ¤
Report Abuse
KnightmareXD is not online. KnightmareXD
Joined: 14 Jul 2009
Total Posts: 11189
09 Jan 2013 08:32 PM
Change:


    if not char or player then return end

to:


    if not char or not player then return end

¤ ¤ † K M X D † ¤ ¤

Report Abuse
noah is online. noah
Joined: 11 Sep 2006
Total Posts: 18977
09 Jan 2013 08:33 PM
do u want2die, nite?
Report Abuse
SockPuppetCow is not online. SockPuppetCow
Joined: 14 Sep 2012
Total Posts: 121
09 Jan 2013 09:01 PM
That worked, Knight
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