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?