You can write your topic however you want, but you need to answer these questions:
I am trying to make it so that when a player drops a gear via the Backspace key it gets deleted after a while.
The issue is that it’s not deleting and it gives me this error:
ServerScriptService.ShirtUnload:16: attempt to index nil with 'Backpack'
This is my current code:
local Workspace = game:GetService("Workspace")
local TweenService = game:GetService("TweenService")
local Players = game:GetService("Players")
Players.LocalPlayer.Backpack.ChildRemoved:Connect(function(shirtTool)
if shirtTool.Name == "Shirt" and shirtTool.Parent == Workspace then task.wait(5)
local tweenInfo = TweenInfo.new(2, Enum.EasingStyle.Linear, Enum.EasingDirection.Out)
local tween = TweenService:Create(shirtTool, tweenInfo, {Transparency = 1})
tween:Play()
tween.Completed:Connect(function()
shirtTool:Destroy()
end)
end
end)
What it’s doing is It detects if a tool is removed from the backpack and it is named: “Shirt” Then it waits 5 seconds and removes it from the game.
I’ve tried making code with DescendantAdded and removing the Tool that way but it just wasn’t working.
I mean, not the prettiest but you could make it much simpler. Just have a script that checks if the parent of the tool is the workspace, and if so wait however long you want then remove it. For example
local Cooldown = 10 -- Any time you want
While wait(1) do
if script.Parent.Name == "Workspace" then
wait(Cooldown)
script.Parent:Destroy()
end
end)
put that as a script inside the tool. I think it would work. Again, not super fancy and im sure there are 100% better ways to do it. But if no one else responds id try that, or something along those lines.
Just removing the tool if its parent is anything other than the Character/players backpack
There isn’t anything wrong with your code, it’s where and what script you’re using. If your script is in Server Script Service then it’s a server script. There is no “LocalPlayer” in a server script, which is why it’s “indexing nil with backpack” as local player doesn’t exist. Change the script to a local script and put it in starter player scripts