Scripting Tool to Backpack Error

I’m Trying to Make A Tool Clone Button for a Morph GUI I have, its supposed to Clone Tools from ServerStorage, to My Player backpack, But I keep Getting “Attempting to Index Nil with Backpack”

This is My Script, Every Define (The Local Tools, And toolCones) Work, But when it gets to Local PlayerBackpack it gives me an error in Output

I have looked through many different pages on this, but When i try to correct the script, using what they had, it Didn’t affect the Nil Error I got

--Defining Local items
local Tool1 = game.ServerStorage["E-11"]
local Tool2 = game.ServerStorage["E-11D"]
local Tool3 = game.ServerStorage["E-11E"]
local Tool4 = game.ServerStorage["F-11D"]
print("Working")
--
print("Working1")
local ToolClone1 = Tool1:Clone()
local ToolClone2 = Tool2:Clone()
local ToolClone3 = Tool3:Clone()
local ToolClone4 = Tool4:Clone()
---------------------------------------------
script.Parent.MouseButton1Click:Connect(function()
	local PlayerBackpack = game.Players.LocalPlayer.Backpack
	ToolClone1.parent = PlayerBackpack
	ToolClone2.parent = PlayerBackpack
	ToolClone3.parent = PlayerBackpack
	ToolClone4.parent = PlayerBackpack
end)

You can’t access local player from a server script.

1 Like

Is this in a localscript? If it isn’t, you can’t access the LocalPlayer from a normal script. If it is in a LocalScript, you can’t access ServerStorage

1 Like

Yeah like he said, if it’s in a local script just move the tools to replicated storage

Yeah, I figured it was something I wasn’t recognising, i’m not a big scripter, im Sorta new to scripting

it was a regular script, is why

Also, as far as I can see, you used a server script in a gui. You have to use local scripts when handling guis as far as I know. You can just use a remote event or click detector.

Well, My problem, is The game the morph is for, I have all access to All Tools, & im to tired of having to manually give myself tools, So I was trying to refrence ServerStorage because The tools I use in the game, Are In ServerStorage, What it was supposed to do, was Detec those Things In ServerStorage & Clone them to My backpack (If its not allowed on roblox, then Ill stop what im doing)

You can place the tools in Replicated Storage and clone them from there

Yeah, like he said you just move the tools to ReplicatedStorage and do game.ReplicatedStorage.Tool etc etc

The problem, is The owner of the game, Doesnt like Having Devs Work on the game, & does it himself because he doesnt trust Devs, Im 1 of his dev friends, for building

Then keep it in server storage and use a remote event.

1 Like

Example:

-- LOCAL SCRIPT
local event = game.ReplicatedStorage.Event


gui.MouseButton1Click:Connect(function()
event:FireServer() -- Fires the event 
end)
-- SERVER SCRIPT

local event = game.ReplicatedStorage.Event
local tool = game.ServerStorage.Tool

event.OnServerEvent:Connect(function(player) -- Detects when a client fires the event and returns *player* based on who fired the event
tool:Clone().Parent = player.Backpack

end)
2 Likes

Ill see if that works, if it does, Thank you for helping me fix this problem.