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

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

Asked by 2 years ago
Edited 2 years ago

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

Log in to vote
0
Answered by 2 years ago
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)
0
Oh wow! It works! Thank you so much! darkkitten12345 8 — 2y
Ad

Answer this question