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

How do I make a tool stop giving to players if they already have one?

Asked by 6 years ago

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?

01local debounce = false
02 
03function getPlayer(humanoid)
04local players = game.Players:children()
05for i = 1, #players do
06if players[i].Character.Humanoid == humanoid then return players[i] end
07end
08return nil
09end
10 
11function onTouch(part)
12 
13local human = part.Parent:findFirstChild("Humanoid")
14if (human ~= nil) and debounce == false then
15 
View all 30 lines...

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??

1 answer

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

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 
04local debounce = false
05 
06script.Parent.Touched:Connect(function(part) --something touched the part
07local 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
20end)
0
Thank you, works perfectly. Yosufgamer -7 — 6y
0
no problem! :) meteorcrasher118 35 — 6y
0
Thank you and I fixed the problem about the shop robloxsario 76 — 6y
Ad

Answer this question