I want to make a brick that simply prints the names of the people who touched it. The catch being once a person touches it the brick can't print ONLY their name for let's say 5 seconds. So I don't think this would use a debounce unless I could make a debounce turn on and off for individual players. I know this is somewhat asking for a script, but I really need an example to go off of and turn into something useful. :(
local isTouched = false local x = script.Parent x.Touched:Connect(function(a) if not isTouched then -- Debounce isTouched = true for i,v in pairs(game.Players:GetChildren()) do print(v.Name) wait(5) isTouched = false end end end)
This script prints all players in the game and I just want the ones who touched it to get a debounce.
In my opinion, the easiest way to do this is to have a table that it puts the user's name into.
local part = script.Parent; local Touched = {}; part.Touched:connect(function(hit) hit = hit.Parent; if hit:IsA("Accessory") then hit = hit.Parent; end; if Touched[hit.Name] == nil then print(hit.Name,"touched",part.Name); Touched[hit.Name] = true; spawn(function() wait(5); Touched[hit.Name] = nil; end); end; end);
It should be as simple as doing that. I haven't tested this code, but it should work. If it doesn't, let me know and I will work on it until it does work. I hope this helped. If it did, if you could accept this answer as the correct one so people know you have been helped, and people with this problem can also find a solution.
If it didn't work, feel free to keep contacting me and I'll help you figure it out until it does work. Also feel free to ask any other questions you have.