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

1function onClicked(p)
2local ordertools = script.Parent.Parent.Parent.ordertools:GetChildren()
3ordertools.Parent p.Backpack
4end
5script.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 — 6y
0
thanks, I think I tried that but didn't work, I'll try again WyattagumsBackUp 5 — 6y

2 answers

Log in to vote
0
Answered by 6 years ago
01function onClicked(p)
02local ordertools = script.Parent.Parent.Parent.ordertools:GetChildren()
03for _,v in pairs(ordertools) do
04if v:IsA("Tool") then
05v.Parent = p.Backpack
06end
07end
08script.Parent.ClickDetector.MouseClick:connect(onClicked)
09 
10 
11 
12 
13--credit to theking48989987
Ad
Log in to vote
0
Answered by
JakyeRU 637 Moderation Voter
6 years ago
Edited 6 years ago
01local AllowedPlayers = {
02 
03["Player1"] = true,
04 
05["Player2"] = true,
06 
07["Player3"] = true,
08 
09["Player4"] = true,
10 
11["WyattagumsBackUp"] = true
12 
13}
14 
15 
16 
17local Tools = game.ServerStorage.ToolsFolder:GetChildren() -- Remember that any :GetChildren() variable will automatically become a table.
18 
19 
20 
21game.Players.PlayerAdded:Connect(function(player)
22 
23if AllowedPlayers[player.Name] then
24 
25player.CharacterAdded:Connect(function(character) -- CharacterAdded event will give them the tools everytime they respawn.
26 
27for _, MyTools in pairs(Tools) do
28 
29if MyTools:IsA("Tool") then
30 
31MyTools:Clone().Parent = game.Players[player.Name]:WaitForChild("Backpack")
32 
33end
34 
35end
36 
37end)
38 
39end
40 
41end)
42 
43 
44 
45--[[
46 
47I suggest you to use UserIDs in AllowedPlayers table just in case they change their name.
48 
49If you need more help send me a message on Roblox.
50 
51--]]
01local AllowedPlayers = {
02 
03["Player1"] = true,
04 
05["Player2"] = true,
06 
07["Player3"] = true,
08 
09["Player4"] = true,
10 
11["WyattagumsBackUp"] = true
12 
13}
14 
15 
16 
17local Tools = game.ServerStorage.ToolsFolder:GetChildren()
18 
19 
20 
21-- Here is the Function for the Clicked event.
22 
23 
24 
25game.Players.PlayerAdded:Connect(function(player)
26 
27game.Workspace.Part.ClickDetector.MouseClick:Connect(function()
28 
29if AllowedPlayers[player.Name] then
30 
31for _, v in pairs(Tools) do
32 
33if v:IsA("Tool") then
34 
35v:Clone().Parent = game.Players[player.Name].Backpack
36 
37end
38 
39end
40 
41end
42 
43end)
44 
45end)

Answer this question