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

Can a script in the workspace call out a tool from inside a player?

Asked by 7 years ago

basically, i have a shop and when players buy an item from it, the item is put into a folder in the player's backpack named "BoughtTools." This is so a script can call out the weapons at any time it likes, and to keep the player from having their weapons in the lobby or just outside the game round in general. But, for some reason, i call out the items in this folder and it does nothing. Its does not give me an error or anything. This is the script below. Do i need to change the parent in any way? Could anyone please tell me whats wrong with it and correct the error? Help is GREATLY appreciated! :)

local plr = game.Players.LocalPlayer
local ShopTools = plr.Backpack.BoughtTools:GetChildren()
local ClonedTools = ShopTools:Clone()
ClonedTools.parent = plr.Bacpack

-TheBlazingMinatour

1 answer

Log in to vote
0
Answered by 7 years ago

Yes, you do need to change the Parent, not parent. Capitalization matters when messing with a part, or any object's, properties. Also, ShopTools is now a table, not just a bunch of objects. You would need to iterate through the function and parent them to the player's Backpack.

Correct code would be

local plr = game.Players.LocalPlayer
local ShopTools = plr.Backpack:WaitForChild("BoughtTools"):GetChildren():Clone()

table.foreach(ShopTools, function(i, v)
    v.Parent = plr.Backpack
end)
0
Thanks! Everthing works only if i remove the :Clone() function tho. It gives me the error, "14:40:52.425 - Workspace.GameScript:67: attempt to call method 'Clone' (a nil value)" Would anyone know how to fix this error? Seabiscuitz 21 — 7y
0
Oh, my bad. Remove the " AlreadyPro 153 — 7y
Ad

Answer this question