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!
Use a larger invisible part that covers the area around the brick and use it as a detector.
I was talking about something like this:
https://imgur.com/a/jE6OY
Also, here is a code that creates an event that fires only when the entire character entered or exited the area:
local T = {} local EvObj = Instance.new("BindableEvent") script.Parent.Touched:Connect(function(p) local Ply = game.Players:GetPlayerFromCharacter(p.Parent) if Ply then if T[Ply.Name] then T[Ply.Name][p.Name]=true else T[Ply.Name]={[p.Name]=true} EvObj:Fire(true,Ply) end end end) script.Parent.TouchEnded:Connect(function(p) local Ply = game.Players:GetPlayerFromCharacter(p.Parent) if Ply then if T[Ply.Name] then T[Ply.Name][p.Name]=nil if #T[Ply.Name]==0 then EvObj:Fire(false,Ply) T[Ply.Name]=nil end end end end) local TouchEvent = EvObj.Event TouchEvent:Connect(function(e,p) print(e,p) end)