While is touching function? Help!
Asked by
7 years ago Edited 7 years ago
Hello guys, I'm having a hard time figuring out how to do a IsTouching function for my script to work, what I want to do is that if the player is in a determined area, can press a button which will animate the player through a parkour vault and then move to the other side of the brick, everything works but not very well.
I tried with Touched and TouchEnded, but each ticks they are both called and this result in the script to work only sometimes.
This is the current code:
01 | brick.Touched:connect( function (otherPart) |
02 | local char = otherPart.Parent |
03 | local hum = char:FindFirstChild( "Humanoid" ) |
05 | local player = game:GetService( "Players" ):GetPlayerFromCharacter(char) |
06 | local flags = player:FindFirstChild( "Flags" ) |
07 | if flags:FindFirstChild( "CanKong" ).Value = = false then |
08 | flags:FindFirstChild( "CanKong" ).Value = true |
09 | flags:FindFirstChild( "KongInstance" ).Value = script.Parent.EndPoint |
15 | brick.TouchEnded:connect( function (otherPart) |
16 | local char = otherPart.Parent |
17 | local hum = char:FindFirstChild( "Humanoid" ) |
19 | local player = game:GetService( "Players" ):GetPlayerFromCharacter(char) |
20 | local flags = player:FindFirstChild( "Flags" ) |
21 | if flags:FindFirstChild( "CanKong" ).Value = = true then |
22 | flags:FindFirstChild( "CanKong" ).Value = false |
23 | flags:FindFirstChild( "KongInstance" ).Value = nil |
I want it to work every time I press the key, and not sometimes!