Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to make a tool only possible to be given to you once? ( With click detector )

I'm not the best scripter, but I want to know how I can make it so when a player clicks it once they get the tool ( That part's done ) But when they click it again it doesn't give it to them because it's in their inventory. I've been thinking about how to approach this but it's kinda difficult.

local CupGiver = script.Parent
local Detector = CupGiver.ClickDetector
local Players = game.Players.LocalPlayer


Detector.MouseClick:Connect(function(Player)
	local Cup = game.ReplicatedStorage.Cup:Clone()
	Cup.Parent = Player.Backpack
	print(Player)
	if Cup.Parent == Player.Backpack then
    

	end

end)

Not sure what to do with the if Cup.Parent thing so the Script knows the character can only have one.

1 answer

✓ Accepted answer
Detector.MouseClick:Connect(function(Player)
   local Character = Player.Character or Player.CharacterAdded:Wait()
   
   if not Player:WaitForChild("StarterGear"):FindFirstChild("Cup") then
      local newCup = game.ReplicatedStorage.Cup:Clone()
      newCup.Parent = Player:WaitForChild("StarterGear")
      
      newCup:Clone().Parent = Character
   else
      print("Player already has the tool 'Cup' in their inventory.")
   end
end)

1 comment

0

Oh wow! It works! Thank you so much!

This discussion is preserved as it was. New answers, comments, and votes are closed.