How can i make the item pick up only once?

Hello, im kinda confuse since im new in creating games here in roblox. My items in inventory duplicating every time i touched/clicked/pick up the item. How can i make the item pick up only once and it will never duplicate?

PS. that script i only got that from a tutorial in youtube.

local tool = game.ReplicatedStorage.Keys["Room 217"]
local giver = script.Parent
local canGive = false

local function GiveTool (player)
	if canGive == false then
		canGive = true
		local clone = tool:Clone()
		clone.Parent = player.Backpack
		wait(1)
		canGive = false
	end
end

giver.ClickDetector.MouseClick:Connect(function(player)
	GiveTool (player)
end)

You already have a Boolean value for this so you just need to remove the part where it makes the player able to get the tool again.

Use the code below. :slight_smile:

local tool = game.ReplicatedStorage.Keys["Room 217"]
local giver = script.Parent
local canGive = false

local function GiveTool (player)
	if canGive == false then
		canGive = true
		local clone = tool:Clone()
		clone.Parent = player.Backpack
	end
end

giver.ClickDetector.MouseClick:Connect(function(player)
	GiveTool (player)
end)
4 Likes

thank you so much for the reference. this help me a lot.

3 Likes