Backpack is not a valid member of Player "Players.localplayer"

hi I need help my localscript does not work what I want it to do is: if a player touches a block that block activates the value fight and after that
a local script if game.players.localscript.backpack.Folder (it’s the folder where I keep the game values). value doesn’t matter if it’s true do such a thing and to see if it worked use a print

local script:

local folder = game.Players.LocalPlayer.Backpack
local Player = game.Players.LocalPlayer

if folder.Folder.FIGHT == “true” then
print(“test”)
end

when i touch the block it works and the value fight is activated but then i get this error
Backpack is not a valid member of Player “Players.localplayer”

If you cannot access a value in backpack or the backpack in a local script, can you help me explaining how I should do something similar?

You have to wait for the backpack to be added, instead use:

local folder = game.Players.LocalPlayer:WaitForChild("Backpack")

I thought that same thing I tried but it didn’t work I get the same error

Surely this is a LocalScript?

local Players = game:GetService("Players")
local Backpack = Players.LocalPlayer:WaitForChild("Backpack")

if Backpack.Folder.FIGHT then
    print("test")
end

There’s no way this does not work unless I am out of my mind and Backpack actually does not exist.

That’s very odd, maybe put a task.wait(5) on top or a game.Loaded function.

Thats not your full local script is it, like you said you want it when a person touches the block. Show the full script

yes is a local script I tried moving the local script to another place and it worked but when I have the value of fight in true
the print(“test”) doesn’t work

What ever youre checking, is it a String Value or a Bool Value? If its a bool, dont put “true”, try just true

local Players = game:GetService(“Players”)
local Part = script.Parent

Part.Touched:Connect(function(Hit)
local Plr = Players:GetPlayerFromCharacter(Hit.Parent) or Players:GetPlayerFromCharacter(Hit.Parent.Parent)
if Plr then
Plr.Backpack.Folder.FIGHT.Value = true
Plr.Backpack.Folder.enemy.Value = 1
wait(3)
print(“a”)
end
end)

thats the script

Does this work? like does the value change

it a bool value

and i put true and doesnt work

If I remember correctly, local scripts dont work if you put them in a part that isn’t controlled by a player (or somethign like that)

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

So what do you suggest to do something similar?

Try literally just putting the entire script in a server script under the same part

Is your local script the touched part? or is it a server script

1 Like

no, its a script
you can see in the script a script.parent

Here is the script for checking.

local Players = game:GetService("Players")
local Backpack = Players.LocalPlayer:WaitForChild("Backpack")
while task.wait(1) do
if Backpack.Folder.FIGHT.Value == true then
		print("true")
	else print("false")
	end
end

This is looped to check if its false or not. This should work now

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.