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

How would I print the names of everyone who has touched a brick once with a debounce of 5 seconds?

Asked by 7 years ago
Edited 7 years ago

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.

1
Could you please add some code showing that you have attempted this? MrLonely1221 701 — 7y

1 answer

Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

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.

0
Hope this helps MrLonely1221 701 — 7y
0
Okay I see whats going on here thanks for giving me something to go off of. I just one question, how would I print that table to output with the players names inside. SimpleFlame 255 — 7y
0
Thanks! This is what I needed. SimpleFlame 255 — 7y
Ad

Answer this question