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

Give inventory to another player script?

So I've got this local script inside of a clickable gui and all

'Username' is a text box the player can enter another players username

local name = game.Players.LocalPlayer
script.Parent.MouseButton1Click:connect(function()
  name.Backpack:GetChildren():Clone().Parent = game.Players:FindFirstChild(script.Parent.Parent.Username.Text).Backpack
name.Backpack:GetChildren():Destroy()
end)

When they click this gui button its supposed to take the players inventory and give it to the other player

It just down right isn't working. I've gone through many methods and rewrites of this but they just will not work.

No errors or anything popping up its just not working at all, the first players items dont get destroyed and the other player doesn't get any items.

Any ideas as to why this isn't working?

Edit: I tried to take peoples items individually that they were holding but that too didnt work

1 answer

✓ Accepted answer

Well, doing object:GetChildren():Clone() will result into an error, cuz as you may now :GetChildren() returns a table containing the object's children. And you can't use :Clone() on a table can you. Always think logiclly when you're scripting, remember what each function returns. I'm not sure if you're famaliour with in pairs loops. I hope you are cuz were gonna use those here. And just in case.

local name = game.Players.LocalPlayer
local wanted = game.Players:FindFirstChild(script.Parent.Parent.Username.Text)

script.Parent.MouseButton1Click:connect(function()
        for i, v in pairs (name.Backpack:GetChildren()) do
		if wanted then
			v.Parent = wanted.Backpack
		end
	end
end)

It's actually that easy! And really sorry for not explaining xd the link I gave you is sure way helpful.

9 comments

0

I tested it with Player1 and Player2 but it didn't seem to work, I tried it with myself so I could see the output and it said Players.barrettr500.PlayerGui.Order.Frame.Accept.GUI Click:2: attempt to index a nil value

0

well that's actually your mistake, i guess what happended is it didn't find the player that had the name that was the same with the text in that text box

0

1 sec ill edit it

0

ok, now if the Text has the same name as the player this should work

0

It wasnt working so I put an else statement on your 'if wanted then' part and it always goes to else, the text should have the same name as the player, I even tried directly copying and pasting the username from Players and into the players gui

0

Hmmm, you want it to give the items to any player or to the chosen one?

0

Ok I just fixed it! the wanted variable had to be after the click because they didnt select who they wanted to be chosen till right before clicking!

0

but sinse its a local script it only goes into the players backpack according to the person sending it, you answered my first question, so now Im starting a new post

0

ok! glad to help

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