This script gives a player an item from ServerStorage called StrikeBall. However, I can not prevent a player from receiving multiple StrikeBalls. This is my attempt:
local Giver = script.Parent local Gear = game.ServerStorage.StrikeBall local debounce = false function onTouch(part) local Player = part.Parent:findFirstChild("Humanoid") if Player ~= nil then if debounce == false then local Location = game:GetService('Players'):GetPlayerFromCharacter(Player.Parent) if Location.TeamColor == Giver.BrickColor then if Location.Character:FindFirstChild("StrikeBall") then print("StrikeBall found in inventory.") elseif Location.Backpack:FindFirstChild("StrikeBall") then print("StrikeBall found in backpack.") else debounce = true local New = Gear:clone() New.Parent = Location.Backpack wait (5) debounce = false end end end end Giver.Touched:connect(onTouch)
I made a helper method to to check and see if the person who touched the giver has the tool or not
local Giver = script.Parent local Gear = game.ServerStorage.StrikeBall local debounce = false local function FindTool(player, tool) local Character = player.Character local HoldingTool = Character:FindFirstChild(tool) local BackpackTool = player.Backpack:FindFirstChild(tool) if HoldingTool ~= nil or BackpackTool ~= nil then return true end end Giver.Touched:connect(function(part) debounce = true local Player = game.Players:GetPlayerFromCharacter(part.Parent) if Player ~= nil and Player.TeamColor == Giver.BrickColor and debounce and Player:FindTool("StrickBall") ~= nil then Gear:Clone().Parent = Player.Backpack end wait(5) debounce = false end)
Just put :FindFirstChild("StrikeBall") ~= nil then
You were really close!