BoolValue is not a valid member of Workspace

  • What do you want to achieve?
    Set a BoolValue (inside Player’s instance) 's value to true whenever the player equips an item

  • What is the issue?
    image

  • What solutions have you tried so far?
    image
    image
    ^^^ Tool Structure Should be right under the player’s backpack whenever cloned ^^^

2 Likes

When a tool is equipped the tool moves inside the character model so it’s not always inside the player backpack.

1 Like

The warning tells you that there is no property of game.Workspace called “ShieldEnabled”, so trying to get or set it is an error. It also tells you that the error happens on line 3 of the script, which is

local shieldstatus = plr.ShieldEnabled

Well, it’s a little weird that we get that error, because your code makes it seem like we’re trying to get a child of the local player. So why is it complaining that we’re trying to get something from workspace? My guess is that plr doesn’t refer to what you think it refers to. To verify, try adding a print(plr and plr:GetFullName()) before line 3. This will tell us exactly what plr refers to, and I’m guessing you’ve accidentally made it refer to workspace. Alternatively, set a breakpoint right before the line where you get an error, and use the script debugging tools to see exactly what each variable refers to.

This also shows how refering to things by long chains of instance.Parent.Parent.Parent.Parent is dangerous, because it makes it very hard to reason about what exactly each variable refers to. It’d be better to have a couple of constants like

local playerScripts = script.Parent
local localPlayer = playerScripts.Parent

and so forth (although I don’t recommend getting the LocalPlayer like that).

2 Likes

Problem was solved
Solution:
The main issue here was mentioned by BenMactavsin:

When a tool is equipped the tool moves inside the character model so it’s not always inside the player backpack.

So, the script.Parent.Parent.Parent with the Equipped event was the workspace, I deleted a .Parent and used Player:GetPlayerFromCharacter(script.Parent.Parent), That got the player’s instance. and then, the issue is solved.

1 Like