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: Script only works once

Previous Thread :: Next Thread 
Gybro is not online. Gybro
Joined: 23 Apr 2014
Total Posts: 808
14 May 2014 05:04 PM
game.Players.LocalPlayer:GetMouse().KeyDown:connect(function(key)
key = key:lower()
if key == "e" then --key
function GetGui()
for i, v in pairs(script:GetChildren()) do
if v:IsA("ScreenGui") then return v end
end
return nil
end
Gui = GetGui()
Gui.Name = script.Parent.Parent.Name .. "TalkGui"
script.Parent.Parent.Changed:connect(function() GetGui().Name = script.Parent.Parent.Name .. "TalkGui" end)
while true do wait(.1)
for i, v in pairs(game.Players:GetChildren()) do
if v.Character ~= nil then
if v.Character:FindFirstChild("Torso") ~= nil and (script.Parent.Position - v.Character.Torso.Position).magnitude <= 5 and v.PlayerGui:FindFirstChild(Gui.Name) == nil then
Gui:Clone().Parent = v.PlayerGui

elseif v.Character:FindFirstChild("Torso") ~= nil and (script.Parent.Position - v.Character.Torso.Position).magnitude > 5 and (script.Parent.Position - v.Character.Torso.Position).magnitude < 7 then
if v.PlayerGui:FindFirstChild(Gui.Name) then v.PlayerGui[Gui.Name]:Remove() end

end
end
end
end

end
end)

---------------

It only works once, when the GUI shows up whenever the player comes into proximity.
Report Abuse
micke3212 is not online. micke3212
Joined: 24 Nov 2009
Total Posts: 3000
14 May 2014 05:08 PM
What you need is a Bool value to check things and remove all locals if there are anything, then just add a script inside the script with this:

while wait(1) do
script.Parent.Disabled = true
script.Parent.Disabled = false
end

That's how I solve my problems...
Report Abuse
Gybro is not online. Gybro
Joined: 23 Apr 2014
Total Posts: 808
14 May 2014 05:13 PM
It worked, but now the GUI won't leave the screen when the part is left OR when "e" is pressed again.
Report Abuse
Gybro is not online. Gybro
Joined: 23 Apr 2014
Total Posts: 808
14 May 2014 05:19 PM
b
Report Abuse
micke3212 is not online. micke3212
Joined: 24 Nov 2009
Total Posts: 3000
14 May 2014 05:21 PM
Like I stated, used a Bool Value inside the script to control movments and use a if bool.Value == true then and a elseif bool.Value == false and then have it were it sets them true...
Report Abuse
Gybro is not online. Gybro
Joined: 23 Apr 2014
Total Posts: 808
14 May 2014 05:28 PM
Worked! Thanks!
Report Abuse
Gybro is not online. Gybro
Joined: 23 Apr 2014
Total Posts: 808
14 May 2014 05:32 PM
Wait, how do I get the GUI to disappear when E is pressed a second time?
Report Abuse
vlekje513 is not online. vlekje513
Joined: 28 Dec 2010
Total Posts: 9057
14 May 2014 05:41 PM
Findfirstchild to see if its there.
If its there > destroy if u clone it.
If its not there > create it
Report Abuse
Gybro is not online. Gybro
Joined: 23 Apr 2014
Total Posts: 808
14 May 2014 05:43 PM
Wait, now when you press E once it won't go away if you walk away from the part, but if you press E a second time then walk away from the part, it disappears.

Help?
Report Abuse
Gybro is not online. Gybro
Joined: 23 Apr 2014
Total Posts: 808
14 May 2014 05:45 PM
(I didn't try vlek's thing yet)
Report Abuse
Gybro is not online. Gybro
Joined: 23 Apr 2014
Total Posts: 808
14 May 2014 05:49 PM
b
Report Abuse
Gybro is not online. Gybro
Joined: 23 Apr 2014
Total Posts: 808
14 May 2014 05:58 PM
Can anyone help? :/
Report Abuse
Gybro is not online. Gybro
Joined: 23 Apr 2014
Total Posts: 808
14 May 2014 06:08 PM
Hello...
Report Abuse
Gybro is not online. Gybro
Joined: 23 Apr 2014
Total Posts: 808
14 May 2014 07:46 PM
Come on..
Report Abuse
Gybro is not online. Gybro
Joined: 23 Apr 2014
Total Posts: 808
15 May 2014 06:45 AM
B
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