Having A Problem Getting A Model Into an Players Backpack

-Whats The Error-
15:00:13.436 Workspace.Bowl.Script:5: attempt to index nil with ‘Backpack’ - Server - Script:5

-Whats Are You using it for-
For A Test Ive been trying to find out the problem for ever.

-Whats The Script Type-
Local Script Because im Trying To Get A Local Player.

-Whats The Script-

local ReplicatedStorage = game:GetService("ReplicatedStorage")

script.Parent.ClickDetector.MouseClick:Connect(function()

local Bowl = ReplicatedStorage:WaitForChild("Bowls"):Clone()

Bowl.Parent = game.Players.LocalPlayer.Backpack

end)

If this is a normal script, LocalPlayer won’t work. Use the player parameter of the clickdetector.MouseClick

local ReplicatedStorage = game:GetService("ReplicatedStorage")

script.Parent.ClickDetector.MouseClick:Connect(function(player)

local Bowl = ReplicatedStorage:WaitForChild("Bowls"):Clone()

Bowl.Parent = player.Backpack

end)

read i said its already in the local script.

This error says different though? It points out “Server”, also, it says the name is just “Script”, which all leads to a normal script.

Okay ill try but thats not the problem the problem is the Backpack there saying an index nil with if you read

  • Whats The Error -

you would find the problem

the script is on the workspace, also in a model in the model theres a click ditecter and in the model theres a script

LocalScripts don’t run in workspace. Again, this leads to it being a server script if it is even running, causing the error. If this was a localscript, 1. It wouldn’t be able to run in workspace, 2. it wouldn’t error on the game.Players.LocalPlayer calling it nil, and 3. the tool/model wouldn’t even clone properly.

What does it run in?? i didnt know.

Just check this info on localscripts

A LocalScript will only run Lua code if it is a descendant of one of the following objects:

  • A Player’s Backpack , such as a child of a Tool
  • A Player’s character model
  • A Player’s PlayerGui
  • A Player’s PlayerScripts .
  • The ReplicatedFirst service

What im getting from it is it can run if its these but i already have an object which is backpack thats index nil in local script.

What I’m getting from what you’re saying is that it is saying the “LocalPlayer” is nil, right? if so, that means that it is obviously not a localscript. Can you show me your explorer?

Alright i just notice that it was not a local script, sorry for the incovience but its not giving me an error once i put it in a local script so it must not be running evan know its say

A LocalScript will only run Lua code if it is a descendant of one of the following objects:

  • A Player’s Backpack , such as a child of a Tool
  • A Player’s character model
  • A Player’s PlayerGui
  • A Player’s PlayerScripts .
  • The ReplicatedFirst service

You did say this is in workspace, right? if so, it won’t run.