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

Clone an item into a folder with Players name?

I am trying to make a button on a Gui (It's a LocalScript) that will clone an item from ReplicatedStorage into their inventory.

PlayerDataCreator:

local SS = game:GetService('ServerStorage')
local data = Instance.new('Folder', SS)
data.Name = 'PlayerData'

game.Players.PlayerAdded:connect(function(plr)
	local player = Instance.new('Folder', data)
	player.Name = plr.Name
		
	local Inventory = Instance.new('Folder', player)
	Inventory.Name = 'Inventory'
end)

Item Clone Gui Script:

wait(1)
local item = game.ReplicatedStorage.Items:WaitForChild('Drop1')
local Player = game.Players.LocalPlayer

function onClicked()
	item:Clone().Parent = game.ServerStorage.PlayerData.Player.Name.Inventory
end
script.Parent.MouseButton1Click:connect(onClicked)

1 answer

✓ Accepted answer

Guessing that the problem is that it doesn't clone, its because of what you have stated in line 6 of your Item Clone Gui Script.

-- Instead of this:
 item:Clone().Parent = game.ServerStorage.PlayerData.Player.Name.Inventory
-- You need this:
item:Clone().Parent = game.ServerStorage.PlayerData[Player.Name].Inventory

This is because lua thinks the path is just Player then Name rather than the actual name of the Player.

Hopefully this works for you.

1 comment

0

Oh, ok I see now! Thanks dude, mind if I message you on ROBLOX for any more help in future?

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