Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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:

01brick.Touched:connect(function(otherPart)
02    local char = otherPart.Parent
03    local hum = char:FindFirstChild("Humanoid")
04    if hum then
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
10            print("Can kong");
11        end
12    end
13end)
14 
15brick.TouchEnded:connect(function(otherPart)
View all 27 lines...

I want it to work every time I press the key, and not sometimes!

0
try remove endpoint darkzerobits 92 — 7y
0
the endpoint is not related to the touched event, it's just the brick where the animation should finish... alessandro112 161 — 7y

1 answer

Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

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:

01local T = {}
02local EvObj = Instance.new("BindableEvent")
03script.Parent.Touched:Connect(function(p)
04    local Ply = game.Players:GetPlayerFromCharacter(p.Parent)
05    if Ply then
06        if T[Ply.Name] then
07            T[Ply.Name][p.Name]=true
08        else
09            T[Ply.Name]={[p.Name]=true}
10            EvObj:Fire(true,Ply)
11        end
12    end
13end)
14script.Parent.TouchEnded:Connect(function(p)
15    local Ply = game.Players:GetPlayerFromCharacter(p.Parent)
View all 30 lines...
0
I did it like this, the problem is that TouchEnded calls at every tick and so my function returns true alessandro112 161 — 7y
1
I'm gonna check when I come home nooneisback 81 — 7y
0
I edited my post nooneisback 81 — 7y
Ad

Answer this question