Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 5 years ago

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!!!

0
move each tool into Backpack using a for loop theking48989987 2147 — 5y
0
thanks, I think I tried that but didn't work, I'll try again WyattagumsBackUp 5 — 5y

2 answers

Log in to vote
0
Answered by 5 years ago
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
Ad
Log in to vote
0
Answered by
JakyeRU 637 Moderation Voter
5 years ago
Edited 5 years ago
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)

Answer this question