What do you want to achieve? I want to make a phase 2 to a class(kinda) and I made a tool that gives you 2 more tools and deletes your current ones.
What is the issue? I have tried going into the backpack and waiting for a child to appear.
local backpack = Players:FindFirstChildOfClass("Backpack")/ --game.Startergui.Parent.Backpack is another one I´ve tried
local swrd = backpack:WaitForChild("Sword")
local MultiSlash = backpack:WaitForChild("Multi-Slash") -- getting the backpack and the tools I want to destroy
local function Activated(Activated)
swrd:Destroy()
MultiSlash:Destroy()
-- I have also tried backpack:ClearAllChildren()
end
Tool.Activated:Connect(Activated)
What solutions have you tried so far? Did you look for solutions on the Developer Hub? I have tried searching for it but I couldn´t find anything
The script for destroying the tool and adding the other tools are in other ones so that I could understand why there were problems.
I’m not a good scripter so maybe that´s why, also, in case it’s necessary, the tools are not in the starter pack but rather in lighting and then cloned into the player´s backpack when a GUI button is pressed(this is my first post so if I got something wrong/didn´t understand something completely please tell me!)
Use a localscript and when the tool is triggered, use RemoteEvents which fire to the server and then remove the tool from the player’s backpack/character.
local Players = game:GetService("Players")
local tool = script.Parent
tool.Activated:Connect(function()
local player = Players:GetPlayerFromCharacter(tool.Parent)
player.Backpack:ClearAllChildren()
end)
I have 2 tools that I wish to destroy, and not any of them are from the tool where the script is, there is already a different script where the tool where all the scripts are is destroyed, but I think you refer to destroying the tools and only used singular, I will be attempting to use the remoteEvent idea anyways, thanks
local players = game:GetService"Players"
local tool = script.Parent
tool.Activated:Connect(function()
local character = tool.Parent
local player = players:GetPlayerFromCharacter(character)
if player then
local humanoid = character:FindFirstChildOfClass"Humanoid"
local backpack = player:FindFirstChildOfClass"Backpack"
if humanoid and backpack then
humanoid:UnequipTools()
for _, tool in ipairs(backpack:GetChildren()) do
if tool:IsA"Tool" then
tool:Destroy()
end
end
end
end
end)