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

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

Asked by
Uglypoe 557 Donator Moderation Voter
8 years ago

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

Log in to vote
0
Answered by 8 years ago
Edited 8 years ago
-- 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.

Ad

Answer this question