01 | local debounce = false |
02 |
03 | function getPlayer(humanoid) |
04 | local players = game.Players:children() |
05 | for i = 1 , #players do |
06 | if players [ i ] .Character.Humanoid = = humanoid then return players [ i ] end -- The error was on this line |
07 | end |
08 | return nil |
09 | end |
10 |
11 | function onTouch(part) |
12 |
13 | local human = part.Parent:findFirstChild( "Humanoid" ) |
14 | if (human ~ = nil ) and debounce = = false then |
15 |
Instead of this:
1 | function getPlayer(humanoid) |
2 | local players = game.Players:children() |
3 | for i = 1 , #players do |
4 | if players [ i ] .Character.Humanoid = = humanoid then return players [ i ] end |
5 | end |
6 | return nil |
7 | end |
You could just do this:
1 | function getPlayer(humanoid) |
2 | return game.Players:GetPlayerFromCharacter(humanoid.Parent) --This gets the player from the character and returns that player or returns nil if the player doesn't exist |
3 | end |
It's much simpler. I hope this helped!
*Note: for more information on :GetPlayerFromCharacter(), click this: GetPlayerFromCharacter