Hey, I am trying to figure out how to get this tool to stop giving to players once they already have one so that they can' t have a lot. I am using this script to give the tool, how would I do this?
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 |
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 |
I am trying to make it so that it stops giving to players who have it, and keep giving to players that don't have it. Is this possible??
I tried to make some edits to your script, for more details check below.
01 | --Edited script, be sure to move this script out of the tool and move it into the block you are going to hit, also move the tool to the server storage. |
02 | --If you don't want to use these changes (^) then just add line 12 and 13 (in my script) to line 21 (in your script) |
03 |
04 | local debounce = false |
05 |
06 | script.Parent.Touched:Connect( function (part) --something touched the part |
07 | local human = part.Parent:FindFirstChild( "Humanoid" ) --tries to find humanoid through the block that touched the part |
08 | if human ~ = nil and debounce = = false then --if debounce is false, and we find the humanoid |
09 | debounce = true --turns on debounce |
10 | local player = game.Players:GetPlayerFromCharacter(human.Parent) --finds the player through the humanoid's parent, which is the character |
11 | if player ~ = nil then --if we find the player |
12 | local tool = player.Backpack:FindFirstChild( "YourToolName" ) --trying to find if the player has the tool |
13 | if tool = = nil then --sees if the player does not have the tool |
14 | game.ServerStorage.YourToolName:Clone().Parent = player.Backpack --gets the tool from server storage and gives it to the player's backpack |
15 | wait( 2 ) |
16 | debounce = false --turns debounce back to false |
17 | end |
18 | end |
19 | end |
20 | end ) |