the code you gave me doesnt work:local toolNames = { -- List of tool names to be…
- User
the code you gave me doesnt work:local toolNames = { -- List of tool names to be protected "BodySwapPotion", "FuseBomb", "GrappleHook", "GrimAxe", "HalloweenBow", "KnightSword", "PurplePotion", "StaffOfHealing" }
game.Players.PlayerAdded:Connect(function(player) player.CharacterAdded:Connect(function(character) character:WaitForChild("Humanoid").Died:Connect(function() for _, toolName in ipairs(toolNames) do local tool = player.Backpack:FindFirstChild(toolName) if tool then tool:Clone().Parent = player.Character tool:Destroy() end end end) end) end)
- Assistant
I'm sorry to hear that the code isn't working for you. Can you please provide more information about the issue you're experiencing? Are you receiving any error messages or unexpected behavior?
- User
when i die tool equips and doesnt come back to my inventory
- Assistant
I apologize for the confusion. It seems like there was an oversight in the code I provided. To ensure that the tool is returned to the player's inventory when they die, you can use the Player.CharacterRemoving event instead of the Character.Died event. Here's the updated code:
local toolNames = { "BodySwapPotion", "FuseBomb", "GrappleHook", "GrimAxe", "HalloweenBow", "KnightSword", "PurplePotion", "StaffOfHealing" } game.Players.PlayerAdded:Connect(function(player) player.CharacterAdded:Connect(function(character) local function removeTools() for _, toolName in ipairs(toolNames) do local tool = player.Character:FindFirstChild(toolName) if tool then local clone = tool:Clone() clone.Parent = player.Backpack tool:Destroy() end end end character:WaitForChild("Humanoid").Died:Connect(removeTools) player.CharacterRemoving:Connect(removeTools) end) end)This updated code will remove the tools from the player's character and clone them back to the player's backpack both when the character dies and when the character is being removed.
- User
doesnt work either
- Assistant
I apologize for the confusion. My mistake again. The issue with the previous code is that it's trying to remove the tools before the character is actually removed. Here's a corrected version of the code:
local toolNames = { "BodySwapPotion", "FuseBomb", "GrappleHook", "GrimAxe", "HalloweenBow", "KnightSword", "PurplePotion", "StaffOfHealing" } game.Players.PlayerAdded:Connect(function(player) player.CharacterAdded:Connect(function(character) local function removeTools(char) for _, toolName in ipairs(toolNames) do local tool = char:FindFirstChild(toolName) if tool then local clone = tool:Clone() clone.Parent = player.Backpack tool:Destroy() end end end character:WaitForChild("Humanoid").Died:Connect(function() removeTools(character) end) player:WaitForChild("PlayerGui").ChildRemoved:Connect(function(child) if child == character then removeTools(character) end end) end) end) - User
it doesnt come back to my inventory
- Assistant
I apologize for the confusion earlier. It seems that my previous suggestion still did not address the issue correctly. After reviewing the code again, I noticed a couple of errors. Here's the updated code that should properly handle returning the tools to the player's inventory:
local toolNames = { "BodySwapPotion", "FuseBomb", "GrappleHook", "GrimAxe", "HalloweenBow", "KnightSword", "PurplePotion", "StaffOfHealing" } game.Players.PlayerAdded:Connect(function(player) player.CharacterAdded:Connect(function(character) local function removeTools() for _, toolName in ipairs(toolNames) do local tool = player.Character:FindFirstChild(toolName) if tool then local clone = tool:Clone() player.Backpack:WaitForChild(toolName, math.huge) clone.Parent = player.Backpack tool:Destroy() end end end character:WaitForChild("Humanoid").Died:Connect(removeTools) player.CharacterRemoving:Connect(removeTools) end) end)
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.