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

Stuck when attempting to replace the .Touched() event with the :wait() method. Help?

So I'm testing a different way to make some of my scripts more efficient by using the :wait() method instead of the .Touched() event, because the .Touched() event can fire multiple times before a debounce can even trigger. My only issue is getting the player after the part is touched. Here is what I have so far:

repeat until game:GetService("Players"):GetPlayerFromCharacter(Part.Touched:wait().Parent) 
--How do we know which Player touched it??

Is there any possible way to find out which Character would've touched the part to trigger the event? All help is appreciated.

1 answer

-- My idea for getting players from touched parts is:
local p=game.GetService'Players'
script.Parent.Touched:connect(function(hit)
p:GetPlayerFromCharacter(hit.Parent)
print(p:GetPlayerFromCharacter(hit.Parent)) -- This should work. Unless I screwed it up somehow.
end)

The reason I did this: loops aren't really needed if you're trying to connect whoever touched the part... You'll have to add debounce to this, and that is probably something you know. Just make it a function, it saves script lag and various other things.. And it'll allow you to do more.

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