System that checks if you have a tool to avoid duplicating tools

Im creating a game in which when you touch a part you get a tool that is saved on the replicated storage. But i don’t want the tool to duplicate, because now you can get as tools as you want by interacting with the block.

So I need help on scripting a system that when you interact with the part it checks if you have the tool that the part gives, and if you have the tool it doesen’t give it, and if you don’t, it gives the tool.

I’ve tried different options but im new at scripting so they don’t work. Below you have the script inside the Proximity Prompt that is inside of a Part.

script.Parent.Triggered:Connect(function(player)
	local Pack = player.Backpack
	local RepStorage = game:GetService("ReplicatedStorage") 
	local Item = RepStorage:WaitForChild('RPG') 
	local ClonedItem = Item:Clone()
	ClonedItem.Parent = Pack
end)

Thanks in advance

1 Like

here you go

script.Parent.Triggered:Connect(function(player)
	local Pack = player.Backpack
	local RepStorage = game:GetService("ReplicatedStorage") 
	local Item = RepStorage:WaitForChild('RPG') 
    if Pack:FindFirstChild(Item.Name) then return end
	local ClonedItem = Item:Clone()
	ClonedItem.Parent = Pack
end)
2 Likes

Thank you so much! It works perfectly!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.