Ad
Log in to vote
0

Touched event doesnt work as proper as i want?

Asked by 1 month ago

Here is my script.

local part1 = nil
script.Parent.RemoteEvent.OnServerEvent:Connect(function(LPx1)
    if LPx1.Character.Humanoid then
        script.Parent.Wedge.Touched:Connect(function(xy)
            if part1 ~= nil then
            print('hi') --it is supposed to print it only once but instead it do it like 50 times
            end
            part1 = xy.Parent
        end)
        wait(.5)
        part1 = nil
    end
end)

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 605 — 1mo
0
but where TheEagle722 114 — 1mo
0
in the touch event AntoninFearless 605 — 1mo
0
can you make me the script please? i only cna lower it to repeat like 5 times:( TheEagle722 114 — 1mo

1 answer

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

Try disconnecting the event after the part is touched.

connection = script.Parent.Wedge.Touched:Connect(function(xy)
    if part1 then
        print("Part touched")
    end

    part1 = xy.Parent

    connection:Disconnect()
end)
0
Thank you so hard. TheEagle722 114 — 1mo
0
np R_alatch 394 — 1mo
Ad

Answer this question