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 » Game Design
Home Search
 

Re: OnTouch help

Previous Thread :: Next Thread 
kaddad14 is not online. kaddad14
Joined: 13 Apr 2013
Total Posts: 649
11 Feb 2016 07:34 PM
Well I've been trying to figure out this darn OnTouch system for a door. So heres what happens. There are 2 parts in front of a door named Detector1 and Detector2 I want it so if someone touches one of these parts (they will have cancollide turned off) a gui that I have already made will pop up and tell the player Press Q to open. So far I got this as a child for Detector1 and it is not working:

script.Parent.Touched:connect(function(onTouch)
if onTouch.Parent:findFirstChild("Humanoid") then
script.Parent.Parent.StarterGui.Open.Frame.TextBox.Visible = true
script.Parent.Parent.StarterGui.Open.Frame.TextBox.Text = "Press Q to close"
end
end)

The script.Parent.Parent.StarterGui.Open.Frame.TextBox is where the gui I want to appear is located. Can anyone help, I tried looking at other sites and their code didnt work.
Report Abuse
RecurringNightmare is not online. RecurringNightmare
Joined: 05 Jul 2012
Total Posts: 15336
11 Feb 2016 07:46 PM
"a gui that I have already made will pop up"

need to clone it to player.PlayerGui.

script.Parent.Touched:connect(function(hit)
player = game.Players:GetPlayerFromCharacter(hit.Parent)
script.GUI:Clone().Parent = player.PlayerGui -- store the GUI inside the script i guess
end)

you'll need UserInputService to detect key input
Report Abuse
kaddad14 is not online. kaddad14
Joined: 13 Apr 2013
Total Posts: 649
11 Feb 2016 07:51 PM
Wait, so I put the gui where and this script in the part? Also what parts do I replace with my guis name?
Report Abuse
RecurringNightmare is not online. RecurringNightmare
Joined: 05 Jul 2012
Total Posts: 15336
11 Feb 2016 07:54 PM
The GUI inside the script, the script inside the part. Replace in my code where it says "GUI" with whatever your GUI is called.
Report Abuse
StudioTM is not online. StudioTM
Joined: 06 May 2013
Total Posts: 3454
11 Feb 2016 08:03 PM
script.Parent.Touched:connect(function(onTouch)
if onTouch.Parent:findFirstChild("Humanoid") then
local plr = game.Players:GetPlayerFromCharacter(onTouch.Parent)
plr.PlayerGui.Open.Frame.TextBox.Visible = true
plr.PlayerGui.Open.Frame.TextBox.Text = "Press Q to close"
end
end)
Report Abuse
kaddad14 is not online. kaddad14
Joined: 13 Apr 2013
Total Posts: 649
12 Feb 2016 02:26 PM
Thanks, just one more question though, How do I make it so the gui goes away after the player leaves the part?
Report Abuse
RecurringNightmare is not online. RecurringNightmare
Joined: 05 Jul 2012
Total Posts: 15336
13 Feb 2016 01:32 AM
ehh add an "X" button so they can close it
Report Abuse
NoobWithAFez is not online. NoobWithAFez
Joined: 21 Oct 2011
Total Posts: 184
13 Feb 2016 02:00 AM
How do you enable UserInputService?


all your tix are belong to us!1
Report Abuse
kaddad14 is not online. kaddad14
Joined: 13 Apr 2013
Total Posts: 649
13 Feb 2016 03:16 AM
Aw the X thing wont work for me becus the gui is low on the screen and would get in the way if were made X to exit. Isnt there a way to have it get located and deleted?
Report Abuse
myactivetestplace is not online. myactivetestplace
Joined: 11 Jul 2015
Total Posts: 3733
13 Feb 2016 03:19 AM
Two good ways is user input service or add a time limit.
Report Abuse
kaddad14 is not online. kaddad14
Joined: 13 Apr 2013
Total Posts: 649
13 Feb 2016 04:03 AM
I feel like the time limit would be faster and easier, how to do it tho? I tried wait and it didnt work

script.Parent.Touched:connect(function(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
script.Open:Clone().Parent = player.PlayerGui
wait(.1)
script.Open.Frame.Delete().parent = player.PlayerGui
end)

x = 0
script.mouse.KeyDown:connect(function(key)--key pressed to open door
script.key = script.key:lower()
if key == "q" then
while x < 18 do
script.Parent.Rotation = script.Parent.Rotation + 5
x = x+1
end
end
end)
Report Abuse
myactivetestplace is not online. myactivetestplace
Joined: 11 Jul 2015
Total Posts: 3733
13 Feb 2016 04:15 AM
.1 = 1/10th of a second. Soo

wait()
script.Parent.Frame:Destroy()
Report Abuse
kaddad14 is not online. kaddad14
Joined: 13 Apr 2013
Total Posts: 649
13 Feb 2016 04:43 AM
Still doesnt work darn, I tried having this under the part that detects the ontouch.

script.Parent.Touched:connect(function(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
script.Open:Clone().Parent = player.PlayerGui
wait()
script.Parent.Frame:Destroy()
end)

x = 0
script.mouse.KeyDown:connect(function(key)
script.key = script.key:lower()
if key == "q" then
while x < 18 do
script.Parent.Rotation = script.Parent.Rotation + 5
x = x+1
end
end
end)

then i tried the wait as a seperate script underneath the textbox and it still wouldnt work.
Report Abuse
myactivetestplace is not online. myactivetestplace
Joined: 11 Jul 2015
Total Posts: 3733
13 Feb 2016 04:44 AM
One thing you could do is over lap the entire frame with an invisible text button that closes it when clicked.
Report Abuse
kaddad14 is not online. kaddad14
Joined: 13 Apr 2013
Total Posts: 649
13 Feb 2016 05:02 AM
Im trying to avoid a manual exit for the gui because that would stop gameplay. is there a exit ontouch function or something?
Report Abuse
alphaboy299 is not online. alphaboy299
Joined: 15 Jun 2013
Total Posts: 1496
13 Feb 2016 05:17 AM
There is a TouchEnded event.
Report Abuse
kaddad14 is not online. kaddad14
Joined: 13 Apr 2013
Total Posts: 649
13 Feb 2016 07:38 AM
can you explain it to me? or ill just google roblox studios touchended
Report Abuse
NoobWithAFez is not online. NoobWithAFez
Joined: 21 Oct 2011
Total Posts: 184
13 Feb 2016 07:39 AM
script.Parent.TouchEnded:connect(function(onTouchEnded)
-- your script
end


all your tix are belong to us!1
Report Abuse
RecurringNightmare is not online. RecurringNightmare
Joined: 05 Jul 2012
Total Posts: 15336
13 Feb 2016 07:54 AM
@kaddad
http://wiki.roblox.com/index.php?title=API:Class/BasePart/TouchEnded

No need to google, use the documentation :) (wiki)
Report Abuse
kaddad14 is not online. kaddad14
Joined: 13 Apr 2013
Total Posts: 649
13 Feb 2016 09:02 AM
Ugh its still not working for some reason

script.Parent.Touched:connect(function(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
script.Open:Clone().Parent = player.PlayerGui
end)

script.parent.TouchEnded:connect(function(otherPart)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
wait(1)
script.Open:Destroy().Parent = player.PlayerGui
end)

I got the part called Detector1 script as a child of Dectector1 and then the gui as a child of the script. What is wrong with it?
Report Abuse
RecurringNightmare is not online. RecurringNightmare
Joined: 05 Jul 2012
Total Posts: 15336
13 Feb 2016 09:12 AM
script.Open:Destroy().Parent = player.PlayerGui

This is the problem ^ By this time the GUI is already in the Player's PlayerGui on their screen so you look for it in and destroy it from the playergui. Also, you should never use Destroy like that. :Destroy() should always be the last thing on a line of code if that makes sense.
Report Abuse
NoobWithAFez is not online. NoobWithAFez
Joined: 21 Oct 2011
Total Posts: 184
13 Feb 2016 09:12 AM
omg how did i not notice that


all your tix are belong to us!1
Report Abuse
kaddad14 is not online. kaddad14
Joined: 13 Apr 2013
Total Posts: 649
13 Feb 2016 09:25 AM
This is what i have so far and it still delete the gui :(

script.Parent.Touched:connect(function(hit)
player = game.Players:GetPlayerFromCharacter(hit.Parent)
script.Open:Clone().Parent = player.PlayerGui
wait(100000)
end)

script.parent.TouchEnded:connect(function(otherPart)
wait(30)
game.Players.player.Playergui.Open:Destroy()
end)

Also I realised that it clones the open gui like 6 or 7 times (upon each touch to the block) which isnt good, and the gui wont delete any of the guis either.
Report Abuse
NoobWithAFez is not online. NoobWithAFez
Joined: 21 Oct 2011
Total Posts: 184
13 Feb 2016 09:28 AM
Umm maybe try doing
this instead of "script.Open:Clone().Parent"
local clone = script.Open:Clone()
clone.Parent = player.PlayerGui


all your tix are belong to us!1
Report Abuse
RecurringNightmare is not online. RecurringNightmare
Joined: 05 Jul 2012
Total Posts: 15336
13 Feb 2016 09:28 AM
script.parent.TouchEnded:connect(function(otherPart)

Always capitalize Parent. It's caps sensitive

game.Players.player.Playergui.Open:Destroy()

You're searching for an object called "player" in game.Players. I'm sure there's a user called "player" but you're unlikely to encounter them in your games :P It's just player.PlayerGui. And keep the line in the touchended event where you define player
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Game Design
   
 
   
  • 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