Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do I move an Item from a Folder to the Player's Inventory?

So I'm trying to make my script move items from a folder into the players inventory but it isn't working. I know for sure my script is flawless!

function onClicked(p)
local ordertools = script.Parent.Parent.Parent.ordertools:GetChildren()
ordertools.Parent p.Backpack
end
script.Parent.ClickDetector.MouseClick:connect(onClicked)

The Tool just stays in the Folder for some reason!!!

2 comments

0

move each tool into Backpack using a for loop

0

thanks, I think I tried that but didn't work, I'll try again

2 answers

function onClicked(p)
local ordertools = script.Parent.Parent.Parent.ordertools:GetChildren()
for _,v in pairs(ordertools) do
if v:IsA("Tool") then
v.Parent = p.Backpack
end
end
script.Parent.ClickDetector.MouseClick:connect(onClicked)




--credit to theking48989987
local AllowedPlayers = {

["Player1"] = true,

["Player2"] = true,

["Player3"] = true,

["Player4"] = true,

["WyattagumsBackUp"] = true

}

  

local Tools = game.ServerStorage.ToolsFolder:GetChildren() -- Remember that any :GetChildren() variable will automatically become a table.

  

game.Players.PlayerAdded:Connect(function(player)

if AllowedPlayers[player.Name] then

player.CharacterAdded:Connect(function(character) -- CharacterAdded event will give them the tools everytime they respawn.

for _, MyTools in pairs(Tools) do

if MyTools:IsA("Tool") then

MyTools:Clone().Parent = game.Players[player.Name]:WaitForChild("Backpack")

end

end

end)

end

end)

  

--[[

I suggest you to use UserIDs in AllowedPlayers table just in case they change their name.

If you need more help send me a message on Roblox.

--]]
local AllowedPlayers = {

["Player1"] = true,

["Player2"] = true,

["Player3"] = true,

["Player4"] = true,

["WyattagumsBackUp"] = true

}

  

local Tools = game.ServerStorage.ToolsFolder:GetChildren()

  

-- Here is the Function for the Clicked event.

  

game.Players.PlayerAdded:Connect(function(player)

game.Workspace.Part.ClickDetector.MouseClick:Connect(function()

if AllowedPlayers[player.Name] then

for _, v in pairs(Tools) do

if v:IsA("Tool") then

v:Clone().Parent = game.Players[player.Name].Backpack

end

end

end

end)

end)

This discussion is preserved as it was. New answers, comments, and votes are closed.