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

Give inventory to another player script?

Asked by 5 years ago
Edited 5 years ago

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

Log in to vote
1
Answered by
starmaq 1290 Moderation Voter
5 years ago
Edited 5 years ago

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.

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 barrettr500 53 — 5y
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 starmaq 1290 — 5y
0
1 sec ill edit it starmaq 1290 — 5y
0
ok, now if the Text has the same name as the player this should work starmaq 1290 — 5y
View all comments (5 more)
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 barrettr500 53 — 5y
0
Hmmm, you want it to give the items to any player or to the chosen one? starmaq 1290 — 5y
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! barrettr500 53 — 5y
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 barrettr500 53 — 5y
0
ok! glad to help starmaq 1290 — 5y
Ad

Answer this question