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

I can't clone items into plr.Backpack?

I'm trying to clone a knife gear into a player's backpack using values for an inventory feature. Simple as that. This is testing things like this so that's why it seems so forced to happen:

game.Players.PlayerAdded:Connect(function(plr)
	local KnifeValue = Instance.new("StringValue", plr)
	wait()
	KnifeValue.Value = game.ServerStorage.DefaultKnife.Name
	if KnifeValue.Value == game.ServerStorage.DefaultKnife.Name then
		game.ServerStorage.DefaultKnife:Clone().Parent = plr.Backpack
	end
end)

When I do that it doesn't show up in my backpack nor in the explorer. If I change plr.Backpack to simply plr, it does show up in the explorer. Is there anything extra I have to add?

5 comments

0

Is code in LocalScript or server script???

0

server

0

try putting it in replicated storage

0

That didn't work Nickiel

0

Have you tried using waitforchild()? Like game.ServerStorage.DefaultKnife:Clone().Parent = plr:WaitForChild("Backpack")

1 answer

game.Players.PlayerAdded:Connect(function(plr)
    local KnifeValue = Instance.new("StringValue")
    KnifeValue.Parent = plr
    KnifeValue.Value = game.ServerStorage:WaitForChild("DefaultKnife").Name
    game.ServerStorage.DefaultKnife:Clone().Parent = plr.Backpack
end)

This is the correct way to do it, also remember it has to be a server script on serverscriptservice, this will work ONCE every player joins, if you also want to do it every time a player respawns, do this:

game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(char)
		local KnifeValue = Instance.new("StringValue")
		KnifeValue.Parent = plr
		KnifeValue.Value = game.ServerStorage:WaitForChild("DefaultKnife").Name
		game.ServerStorage.DefaultKnife:Clone().Parent = plr.Backpack
	end)
end)

Hope I helped!

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