so i have a basic raycast gun and im trying to clean everything up when the player resets
after reseting i get an error: Players.GeneralBadNews.Backpack.gun.remoteCleaner:9: attempt to index nil with ‘IsA’
heres my cleaner script:
local tool = script.Parent
script.Parent = game.ServerScriptService
local deleteEvent
function respawnCheck(replicator)
local parent
local target
if tool.Parent:IsA("Backpack") then
parent = game.Players
target = tool.Parent
elseif tool:FindFirstAncestorWhichIsA("Workspace") then
parent = tool.Parent.Parent
target = tool.Parent
else
parent = tool.Parent
target = tool
end
deleteEvent = parent.DescendantRemoving:Connect(function(child)
if child == target then
print("cleaning up")
replicator:Destroy()
else
deleteEvent:Disconnect()
respawnCheck(replicator)
end
end)
end
script.Event.Event:Connect(function(replicator)
respawnCheck(replicator)
end)