Trying to make a one time use tool

HI! I have this tool that I want only to be used one time. When the player equips the clicks with the tool equipped, it runs this:

function onFluteLaunch(flute)
	local origCam = workspace.CurrentCamera:Clone()
	Player.OwnedTools.Nuke:Destroy()
	
	

As you can see with this line:

Player.OwnedTools.Nuke:Destroy()

It destroys the nuke tool from their folder. This all works.

Then, when the player buys it from the shop again, it runs this function:

ToolSelectedRE.OnServerEvent:Connect(function(plr, tool)
	if not tool or typeof(tool) ~= "Instance" then return end -- we still want this here just in case

	local ownedTool = plr.OwnedTools:FindFirstChild(tool.Name)




	if not ownedTool then
		print(plr.Name," is buying the ",tool.Name," tool.")

		local price = tool.Price.Value
		local coins = plr.leaderstats.Coins

		if price <= coins.Value then
			coins.Value -= price

			local newTool = tool:Clone() do
				newTool.Parent = plr.OwnedTools



			end
		end
	elseif ownedTool then
	
		local previoustool = plr.Backpack:FindFirstChildOfClass('Tool')
		
		if previoustool ~= nil then
			previoustool:Destroy()
		end
		
		
		if plr.Backpack:FindFirstChild(tool.Name) == nil then
			if plr.Backpack:FindFirstChildOfClass('Tool') then
				plr.Backpack:FindFirstChildOfClass('Tool'):Destroy()
			end
			print(plr.Name," equipped ",tool.Name," tool.")

			local new = tool:Clone()
			new.Parent = plr.Backpack

		elseif plr.Backpack:FindFirstChild(tool.Name) then
			print("triggered")

			local deleted = plr.Backpack:WaitForChild(tool.Name)
			deleted:Destroy()

		end
	end
end)

The problem is, it still thinks the tool is apart of ownedTools which it isn’t. I double checked the player’s OwnedTools folder and nuke isn’t there so I don’t understand why the script thinks the nuke tool is still apart of this folder. Because the script thinks the tool is apart of the folder, the nuke tool is automatically equipped from the shop which isn’t what I want. How do I fix this?

Is this in a LocalScript? It may be replication problems.

Yeah, its in a local script. Let me change it to a regular script.

No, you should just fire an event to the server saying to destroy the flute, or make another ServerScript that deletes the flute when it’s activated. I don’t believe workspace.CurrentCamera works on ServerScripts.

Yeah that is what I am doing right now, hold on and i’ll get back to you :smiley:

local function OnActivated()
	--Run the tool's 'Activated' code.
	Tool:Destroy() --Destroy the tool when finished.
end

Tool.Activated:Connect(OnActivated)