|
| 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 |
|
|
|
| 22 Aug 2014 10:39 AM |
| because another parts is touching it. |
|
|
| Report Abuse |
|
|
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
|
  |
| 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 |
|
|
|
| 22 Aug 2014 10:49 AM |
Can you explain please?
I'm only asking for intention to increase my scripting skills.. |
|
|
| Report Abuse |
|
|
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 |
|
|