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

how to stop touch event spam?

Asked by 5 years ago

local part = script.Parent

part.Touched:Connect(fuction() print("touched") end)

part.TouchedEndded:Connect(fuction() print("touched removed") end)

if you try this script. if you walked in the part it will spam "touched" and "touched removed" at the same time, i want it to print once. like voting a map if you touched the part it will + the number once, if you touchendded it - the number once. please help!

0
can you try mine anyway? because im bad at explaining 3wdo 198 — 5y

3 answers

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago
local part = script.Parent
touched = false -- global variable so it can be used everywhere in the script
part.Touched:Connect(function()
if touched == false then --checks if it has been touched before
print("touched") 
end
end)

part.TouchedEnded:Connect(function() print("touched removed") end)

hopefully this works, I have corrected some of ur typos and added an if statement to check if it has been touched before.

0
doesn't work :C ImAnonymousBan 24 — 5y
0
do you get any erros in the output? wiktorwiktor12 0 — 5y
Ad
Log in to vote
0
Answered by
3wdo 198
5 years ago
local part = script.Parent
debounce = false
part.Touched:Connect(function(hit)
    if not debounce then
        debounce = true
        print("touched")
        wait(5) --waits 5 seconds before it you can print it again change it to whatever time you want
        debounce = false 
    end
end)

Hopefully This Helps.

0
no thats not what i mean... but thanks. ImAnonymousBan 24 — 5y
0
i mean is if player touched it. it will print it once until the player leave the block then get back in! ImAnonymousBan 24 — 5y
0
you can use touchended to tell when the player stops touching the brick but its a bit wonky royaltoe 5144 — 5y
Log in to vote
0
Answered by
IcyMizu 122
5 years ago
local part = script.Parent
local debounce = false
part.Touched:Connect(fuction(hit) 
if debounce == false and hit.Parent:FindFirstChild("Humanoid") then -- checking if debounce is == true and if it finds the humanoid in the model humanoid is a property of the plr model so if it finds it it will find the "player"
debounce = true-- setting it true so it wont be spammed
print(hit.Parent.Name)-- prints the players name
wait(5)-- cooldown for the block
debounce = false-- making it false again so it will be able to work again
end)

Answer this question