for _, tool in ipairs(game:GetService("ReplicatedStorage"):FindFirstChild(nameOfDead.."'s Tools"):GetChildren()) do
print("RANTHEIPAIRSLOOKINGFORFOLDERCHILDREN")
if tool == nil then
WarnGUIEvent:FireClient(player, "Looting", nameOfDead.."'s Body seems to be Empty.", 3, Color3.fromRGB(255, 0, 4))
game:GetService("ReplicatedStorage"):FindFirstChild(nameOfDead .. "'s Tools"):Destroy()
else
tool.Parent = player.Backpack
game:GetService("ReplicatedStorage"):FindFirstChild(nameOfDead .. "'s Tools"):Destroy()
WarnGUIEvent:FireClient(player, "Looting", "You Succsessfully looted "..nameOfDead.."'s Body.", 3, Color3.fromRGB(255, 0, 4))
end
end
When you do a for loop for a getchildren in an empty folder, it doesn’t run at all; because there’s nothing to run for. To check if it’s ran, use a bool variable local var = false
just put var = true right after the for loop, and if there is a child, it’ll turn the variable true, and if it’s not, then the variable will stay false
local var = false
for i,v in pairs(whatever:GetChildren()) do
var = true
end
if var then
--children do stuff
else
--no children do stuff
end
The script basically tries to look for something that doesnt exist, and expects to find something, naturally it will error, so you should utilize the FindFirstChild function a bit better
Here’s an example
local toolParent = tool.Parent
local toolName = tool.Name
if toolParent:FindFirstChild(toolName) then
print("Tool Found")
end
Why would you ever do that?!? Use the length operator!
if #whatever:GetChildren() > 0 then
-- at least 1 child
end
But the problem here is that, :FindFirstChild most likely returned nil, :GetChildren never returns nil. So check that first.
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local tools = ReplicatedStorage:FindFirstChild(nameOfDead .. "'s Tools")
if tools then
-- continue here
end
the thing is when i completly removed any check and tried to parent it instantly. It worked only when the folder was empty i got the error saying nil.
the thing is that when i reset my tools disappear before even going into that folder, but when i kill myself with admin command my tools go into the folder
what in the roblox universe is going on, is reset deleting my backpack or sum ?
yea im doing that rn i want to try all solutions i tried bens first cause he responded first.
my brain just had to think i came up with this now
local toolsfolder = RS:FindFirstChild(nameOfDead.."'s Tools")
if toolsfolder then
for _, tools in ipairs(RS:FindFirstChild(nameOfDead.."'s Tools"):GetChildren()) do
print("RANTHEIPAIRSLOOKINGFORFOLDERCHILDREN")
if tools > 0 then
tools.Parent = player.Backpack
game:GetService("ReplicatedStorage"):FindFirstChild(nameOfDead .. "'s Tools"):Destroy()
WarnGUIEvent:FireClient(player, "Looting", "You Succsessfully looted "..nameOfDead.."'s Body.", 3, Color3.fromRGB(255, 0, 4))
else
WarnGUIEvent:FireClient(player, "Looting", nameOfDead.."'s Body seems to be Empty.", 3, Color3.fromRGB(255, 0, 4))
game:GetService("ReplicatedStorage"):FindFirstChild(nameOfDead .. "'s Tools"):Destroy()
end
end
end
i reseted once and i also used ingame command to kill me once, there are 2 folders but looting dosent work.
here is the full code from beginning
lootBodyBar.OnServerEvent:Connect(function(player)
print("OhNoBeginns")
if player.Character:WaitForChild("Humanoid").Health > 0 and game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId, 20129787) or player.MembershipType == Enum.MembershipType.Premium or player.UserId == 192311210 or player.UserId == 111049139 or player.UserId == 125165008 or player.UserId == 30698801 or player.UserId == 73508343 then
print("YeaUserisGucci")
if player.PlayerGui:FindFirstChild("LootProgressGui") then
player.PlayerGui:FindFirstChild("LootProgressGui"):Destroy()
end
print("yo")
local toolsfolder = RS:FindFirstChild(nameOfDead.."'s Tools")
if toolsfolder then
for _, tools in ipairs(RS:FindFirstChild(nameOfDead.."'s Tools"):GetChildren()) do
print("RANTHEIPAIRSLOOKINGFORFOLDERCHILDREN")
if tools > 0 then
tools.Parent = player.Backpack
game:GetService("ReplicatedStorage"):FindFirstChild(nameOfDead .. "'s Tools"):Destroy()
WarnGUIEvent:FireClient(player, "Looting", "You Succsessfully looted "..nameOfDead.."'s Body.", 3, Color3.fromRGB(255, 0, 4))
else
WarnGUIEvent:FireClient(player, "Looting", nameOfDead.."'s Body seems to be Empty.", 3, Color3.fromRGB(255, 0, 4))
game:GetService("ReplicatedStorage"):FindFirstChild(nameOfDead .. "'s Tools"):Destroy()
end
end
end
else
print("YeaUserAintGucci")
player.PlayerGui:FindFirstChild("LootProgressGui"):Destroy()
WarnGUIEvent:FireClient(player, "Nice Try", "Nice try bro, looks like wont work", 3, Color3.fromRGB(255, 0, 4))
end
end)