I've been having this problem for 2-3 weeks, and it has been one of the biggest, if not, the biggest problems I've faced during scripting.
What I want to do is make a normal script in a block that will get a player's backpack tools when they touch the block and put ALL of their tools in a folder in ReplicatedStorage.
However, I have never got the right results. It would end up putting ONLY ONE item in a folder, or simply do nothing. I have put print("Number") along the script to see if the script can successfully function parts of the script.
I've also altered the scripts and before I knew it, I've gotten from only a few lines to a lot of lines in the script.
If anyone is able to help me, I would be very happy. I am a Lua beginner so please don't judge me. :)
Here is my script:
script.Parent.Touched:Connect(function(hit)
if debounce == true then
debounce = false
if hit.Parent:FindFirstChild("Humanoid") then
local toolFolder = Instance.new("Folder")
toolFolder.Name = game.Players:GetPlayerFromCharacter(hit.Parent).UserId
print("1")
wait(1)
if game.ReplicatedStorage.PlayerTools:FindFirstChildWhichIsA("Folder") then
print("1.25")
if game.ReplicatedStorage.PlayerTools:FindFirstChildWhichIsA("Folder").Name == game.Players:GetPlayerFromCharacter(hit.Parent).UserId then
print("1.5")
toolFolder:Destroy()
else
local tools = game.Players.GetPlayerFromCharacter(hit.Parent).Backpack:GetChildren()
toolFolder.Parent = game.ReplicatedStorage.PlayerTools
toolFolder.Name = "toolFolder"
repeat
for i = 1, #tools do
tools[i].Parent = game.ReplicatedStorage.PlayerTools.toolFolder
toolFolder.Name = game.Players:GetPlayerFromCharacter(hit.Parent).UserId
print("2. Win!")
end
until
#game.Players.GetPlayerFromCharacter(hit.Parent).Backpack:GetChildren() < 1
wait(1)
debounce = true
end
else
local tools = game.Players.GetPlayerFromCharacter(hit.Parent).Backpack:GetChildren()
toolFolder.Parent = game.ReplicatedStorage.PlayerTools
toolFolder.Name = "toolFolder"
repeat
for i = 1, #tools do
tools[i].Parent = game.ReplicatedStorage.PlayerTools.toolFolder
toolFolder.Name = game.Players:GetPlayerFromCharacter(hit.Parent).UserId
print("3. Win!")
end
until
#game.Players.GetPlayerFromCharacter(hit.Parent).Backpack:GetChildren() < 1
wait(1)
debounce = true
end
end
end
end)
If you would want to test anything for whatever reason, make sure there is a Part with the script I pasted in the Workspace and a folder named "PlayerTools" in ReplicatedStorage. Thank you very much in advance. Sorry if this is really long.