script.Parent.Parent = game.Players.LocalPlayer.Backpack - needing help

Howdy!

I am making a script where the player presses a tool, and it goes into their inventory. However, when I click it, it doesn’t do anything. It is a local script located inside the tool.

Here’s the script:

  script.Parent.ClickDetector.MouseClick:Connect(function()
script.Parent.Parent = game.Players.LocalPlayer.Backpack
end)

Any help?

Nothing is in the output by the way.

script.Parent.ClickDetector.MouseClick:Connect(function(chr)
local tool = game:GetService(“ServerStorage”).TOOL:Clone()
local plr = game.Players:GetPlayerFromCharacter(chr)
tool.Parent = plr.BackPack
end)

Need to be an Server Side script

1 Like

I tried your script, and the output said:

  18:21:43.557 - Workspace.Cutters.Script:4: attempt to index nil with 'Backpack'

Shouldn’t this work? I have changed it to a regular script inside the tool.

Insert a script inside the part, not a localscript
Use PlayerWhoClicked rather than localplayer

script.Parent.ClickDetector.MouseClick:Connect(function(playerWhoClicked) --function
local player = playerWhoClicked --player who clicked
local tool = script.Parent.Tool --index the tool and the tool name
local newtool = tool:Clone() --clone it
newtool.Parent = player.Backpack --clone it into the players backpack
end)

I hope this helped a tiny bit!

1 Like

Uh… I would suggest adding a WaitForChild() because it seems like it’s running as soon as the server starts, It would explain this;

  18:21:43.557 - Workspace.Cutters.Script:4: attempt to index nil with 'Backpack'

Since the Backpack isn’t loaded, it’s indexing a nil object.

Try this;

script.Parent.ClickDetector.MouseClick:Connect(function()
    script.Parent.Parent = game.Players.LocalPlayer:WaitForChild("Backpack")
end)
2 Likes

Thanks! It did help! It now works!

2 Likes

robloxapp-20200419-1836562.wmv (825.7 KB)

Here is the new problem. When I try and open the tool, it doesn’t appear though. How come?

2 Likes

The tool might not have a part named “Handle”
The Handle is the part that will show in the players hand.

(sorry for the late reply, I was developing something)

1 Like

Nono, it’s called Handle. …

2 Likes

That is very weird, I can’t view .wmv files on my computer so I just took a guess, is the tool anchored?, is it transparent?.

1 Like

anchored = false, transparency = 0

1 Like

Try Parenting the tool to serverstorage.
(and make sure that it is a NORMAL script

script.Parent.ClickDetector.MouseClick:Connect(function(playerWhoClicked) --function
local player = playerWhoClicked --player who clicked
local tool = game.ServerStorage.Tool --index the tool and the tool name
local newtool = tool:Clone() --clone it
newtool.Parent = player.Backpack --clone it into the players backpack
end)
1 Like