Problem with duplicated tools

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I need that tools can only be grabbed once by the same player as long as the item is already in its backpack

  2. What is the issue? Include screenshots / videos if possible!
    When the player touches the tool, he grabs it. After the tool respawns, he can touch it again and the tool duplicates.

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    Ive been checking videos, tutorials and posts. Also some scripts from toolbox and editing all to fit but cant seem to make em work, im new to scripting.

Im having alot of trouble with this for some reason, i will keep looking but if anyone could help with this it would be greatly appreciated as nothing seems to work so far. Also, im not very sure where to put the script that would fix it.

Here is my respawning tool script in case it helps, i found it in the toolbox (its a part in the workspace that seems to clone the tool i put above it)

-- See if I have a tool
local spawner = script.Parent
local tool = nil
local region = Region3.new(Vector3.new(spawner.Position.X - spawner.Size.X/2, spawner.Position.Y + spawner.Size.Y/2, spawner.Position.Z - spawner.Size.Z/2),
   Vector3.new(spawner.Position.X + spawner.Size.X/2, spawner.Position.Y + 4, spawner.Position.Z + spawner.Size.Z/2))
local parts = game.Workspace:FindPartsInRegion3(region)
for _, part in pairs(parts) do
	if part and part.Parent and part.Parent:IsA("Tool") then
		tool = part.Parent
		break
	end
end

local configTable = spawner.Configurations
local configs = {}
local function loadConfig(configName, defaultValue)
	if configTable:FindFirstChild(configName) then
		configs[configName] = configTable:FindFirstChild(configName).Value
	else
		configs[configName] = defaultValue
	end
end

loadConfig("SpawnCooldown", 1)

if tool then
	tool.Parent = game.ServerStorage
	
	while true do
		-- put tool on pad
		local toolCopy = tool:Clone()
		local handle = toolCopy:FindFirstChild("Handle")
		toolCopy.Parent = game.Workspace
		local toolOnPad = true
		local parentConnection
		parentConnection = toolCopy.AncestryChanged:connect(function()
			if handle then handle.Anchored = false end
			toolOnPad = false
			parentConnection:disconnect()
		end)
		if handle then
			handle.CFrame = (spawner.CFrame + Vector3.new(0,handle.Size.Z/2 + 1,0)) * CFrame.Angles(-math.pi/2,0,0)
			handle.Anchored = true
		end
		-- wait for tool to be removed
		while toolOnPad do 
			if handle then
				handle.CFrame = handle.CFrame * CFrame.Angles(0,0,math.pi/60)
			end
			wait() 
		end
		
		-- wait for cooldown
		wait(configs["SpawnCooldown"])		
	end
	
end

Thanks beforehand :slight_smile:

what code do you use for handling the tool pick up?
You should check in the player backpack for a child of same name and if there do not allow the pickup to complete.

Yes, you should do what RamJoT said. To check if a player has duplicated tool, do:

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local toolName = "NAME_OF_TOOL"
local counter = 0

character.ChildAdded:Connect(function()
   counter = 0

   for i, v in pairs(character:GetChildren()) do
      if v.Name == toolName then
         counter += 1
      end

      if counter > 1 then
         -- Insert your code here
         -- Code here will run if player picks up a tool and has a duplicate of it
      end
   end
end
1 Like

Thanks for the replies so far guys, where should i put this script? Im assuming inside ServerScriptService? Sorry english is not my main language. Also, about what RamJoT said, i do not have a code that handles the tool pick up, its just a tool that gets picked when you get closed, from what i understand, because of the handle.

You could use code to handle the childadded event for the BackPack to manage the pickup.

Thanks for the help i managed to make it work :slight_smile:

1 Like