Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

how to stop touch event spam?

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!

1 comment

0

can you try mine anyway? because im bad at explaining

3 answers

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.

2 comments

0

doesn't work :C

0

do you get any erros in the output?

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.

3 comments

0

no thats not what i mean... but thanks.

0

i mean is if player touched it. it will print it once until the player leave the block then get back in!

0

you can use touchended to tell when the player stops touching the brick but its a bit wonky

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.