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:
brick.Touched:connect(function(otherPart)
local char = otherPart.Parent
local hum = char:FindFirstChild("Humanoid")
if hum then
local player = game:GetService("Players"):GetPlayerFromCharacter(char)
local flags = player:FindFirstChild("Flags")
if flags:FindFirstChild("CanKong").Value == false then
flags:FindFirstChild("CanKong").Value = true
flags:FindFirstChild("KongInstance").Value = script.Parent.EndPoint
print("Can kong");
end
end
end)
brick.TouchEnded:connect(function(otherPart)
local char = otherPart.Parent
local hum = char:FindFirstChild("Humanoid")
if hum then
local player = game:GetService("Players"):GetPlayerFromCharacter(char)
local flags = player:FindFirstChild("Flags")
if flags:FindFirstChild("CanKong").Value == true then
flags:FindFirstChild("CanKong").Value = false
flags:FindFirstChild("KongInstance").Value = nil
print("Cannot kong");
end
end
end)
I want it to work every time I press the key, and not sometimes!

2 comments
try remove endpoint
the endpoint is not related to the touched event, it's just the brick where the animation should finish...