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

Touched event doesnt work as proper as i want?

Asked by 4 years ago

Here is my script.

01local part1 = nil
02script.Parent.RemoteEvent.OnServerEvent:Connect(function(LPx1)
03    if LPx1.Character.Humanoid then
04        script.Parent.Wedge.Touched:Connect(function(xy)
05            if part1 ~= nil then
06            print('hi') --it is supposed to print it only once but instead it do it like 50 times
07            end
08            part1 = xy.Parent
09        end)
10        wait(.5)
11        part1 = nil
12    end
13end)

How do i make the touch function remote only once not 9999 times? note that that script is undone yet.

0
add a debounce AntoninFearless 622 — 4y
0
but where TheEagle722 170 — 4y
0
in the touch event AntoninFearless 622 — 4y
0
can you make me the script please? i only cna lower it to repeat like 5 times:( TheEagle722 170 — 4y

1 answer

Log in to vote
1
Answered by
R_alatch 394 Moderation Voter
4 years ago

Try disconnecting the event after the part is touched.

1connection = script.Parent.Wedge.Touched:Connect(function(xy)
2    if part1 then
3        print("Part touched")
4    end
5 
6    part1 = xy.Parent
7 
8    connection:Disconnect()
9end)
0
Thank you so hard. TheEagle722 170 — 4y
0
np R_alatch 394 — 4y
Ad

Answer this question