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: Little TouchConnect

Previous Thread :: Next Thread 
GhostLife5555 is not online. GhostLife5555
Joined: 22 Mar 2011
Total Posts: 94
22 Aug 2014 10:37 AM



script.Parent.Touched:connect(function()
script.Parent.BrickColor = BrickColor.new("Bright red")
end)

Hey so.. Here is the script...


Everytime I join it's already red before I touched it.


It's supposed to turn only when I touch it...

Help please!
Report Abuse
CaptainSource is not online. CaptainSource
Joined: 08 Jun 2013
Total Posts: 848
22 Aug 2014 10:39 AM
because another parts is touching it.
Report Abuse
sayhisam1 is not online. sayhisam1
Joined: 25 Nov 2009
Total Posts: 2092
22 Aug 2014 10:41 AM
script.Parent.Touched:connect(function(player)
if player:findFirstChild("Humanoid") then
script.Parent.BrickColor = BrickColor.new("Bright red")
else
print("Not a player!")
end)
try that script instead.
Report Abuse
sayhisam1 is not online. sayhisam1
Joined: 25 Nov 2009
Total Posts: 2092
22 Aug 2014 10:44 AM
Wait,Use this one. That one doesn't work, forgot something.

script.Parent.Touched:connect(function(player)
if player.Parent:findFirstChild("Humanoid") and touching == false then
touching = true
script.Parent.BrickColor = BrickColor.new("Bright red")
wait(1)
touching = false
else
print("Not a player!")
end
end)
Report Abuse
GhostLife5555 is not online. GhostLife5555
Joined: 22 Mar 2011
Total Posts: 94
22 Aug 2014 10:49 AM
Can you explain please?

I'm only asking for intention to increase my scripting skills..
Report Abuse
sayhisam1 is not online. sayhisam1
Joined: 25 Nov 2009
Total Posts: 2092
22 Aug 2014 11:03 AM
script.Parent.Touched:connect(function(player) --The Player part of this is called an argument, it allows the whole function to access whatever touched the part

if player.Parent:findFirstChild("Humanoid") and touching == false then --Ok, let's split this up. The player.Parent is there because if something like a player's Leg touches the part, then only that leg will be "player". You gotta have the character as a whole, so you put a parent. The findFirstChild is there to check if the character as a whole is a player or not. Since findFirstChild returns false if it doesn't find what it's looking for, this line is basically asking "If I find the Humanoid in the parent of the part that touched the brick, then...)". The touching == false part is called a debounce. It's essentially something which prevents a script from being called more than once, especially in a touched() script, since roblox's touch handler calls multiple times for 1 touch. That means that your script will run multiple times for 1 touch. This prevents that from happening.

touching = true-- Like I stated earlier, this is part of the debounce. It sets the debounce value to true, so that the script won't re-execute.

script.Parent.BrickColor = BrickColor.new("Bright red") --You know what this does

wait(1)--This makes the script wait(1) before turning the debounce off, so that multiple touches within 1 second won't re execute the script

touching = false -- This changes the debounce value back to false, so that the script can run again

else-- If the humanoid is not found in the if statement, then this executes

print("Not a player!") --Just prints a message so we know what is happeninga

end--Ends the If statement

end)--Ends the connect

Hopefully that helped.
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