I have an issue. I was trying to make a script where a random tool is selected from ServerStorage and placed in the Player’s backpack, but I got this error:
“Backpack is not a valid member of Player “Players.ParkCityUSA” - Client - LocalScript:2”
Here’s the script, which is in StarterPlayerScripts.
local Players = game:GetService("Players")
local backpack = Players.LocalPlayer.Backpack
local ServerStor = game:GetService("ServerStorage")
local servstorTools = {ServerStor.ClassicSword, ServerStor.MP5K, ServerStor.AdventurerSword}
local randIndex = math.random(1, #servstorTools)
local backpack = Players.LocalPlayer:FindFirstChildOfClass("Backpack")
if backpack then
for i = 1,3 do
servstorTools[randIndex]:Clone().Parent = backpack
wait(2)
end
end
@Auxicon I needed to delete line 2 in order to solve the bug. Must have slipped my mind. @BirdieGoodMan What could be a possible solution to this? Should I put it somewhere else?
It seems that on line 2, the backpack is not found. Since this is a LocalScript, it is likely that the backpack has not loaded in yet.
local Players = game:GetService("Players").LocalPlayer
repeat task.wait() until Players.Character -- Not recommended, but it will still yield for the player character
local backpack = Players.Backpack
As for your ServerStorage problem, the client has access to the ReplicatedStorage. Put all your models there if you want to reference them from the client