Trying to refer to an existing BoolValue, but console only returns error: "is not a valid member of Model"

  1. What do you want to achieve? Keep it simple and clear!
    I want the “Selected” BoolValue to be toggled when a unit is clicked on. I want to then use this BoolValue to restrict whether or not the player can move the unit.

  2. What is the issue? Include screenshots / videos if possible!
    I try to change the “Selected” value in my script, but it returns with an error that states “Selected is not a valid member of Model ‘Workspace.Unit’.” From my end, both on the client and server, however, “Selected” is under Workspace.Unit. I can’t figure out why the script thinks that the BoolValue doesn’t exist under the Unit.

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I searched on the DevFourm for similar issues, but I couldn’t find any solutions that applied to my issue. Most of them were people making typos which hopefully isn’t the case here since I’ve checked multiple times… That would be embarrassing.

Here is my code, I will separate both scripts which are relevant into separate codeblocks. I’m a novice scripter, so my code is likely very messy. Any tips on how I can improve my code are also very appreciated!

PathfindingScript (server script)

local PathfindingService = game:GetService("PathfindingService")
local humanoid = script.Parent:WaitForChild("Humanoid")
local torso = script.Parent:WaitForChild("Torso")
local goalEvent = game:GetService("ReplicatedStorage"):WaitForChild("goalPos")
local pawnteam = script.Parent:WaitForChild("Team").Value

script.Parent:WaitForChild("Torso").BrickColor = pawnteam

local function newGoal(player, position, target)
	if player.TeamColor == pawnteam then
		if target.Parent:FindFirstChild("HumanoidRootPart") ~= nil then
			if target.Parent.Selected == true then
				target.Parent.Selected = false
			else
				target.Parent.Selected = true
			end
		else
			if target.Parent.Selected == true then
				local path = PathfindingService:CreatePath()
				path:ComputeAsync(torso.Position, position)
				local waypoints = path:GetWaypoints()

				for i, waypoint in pairs(waypoints) do
					humanoid:MoveTo(waypoint.Position)
					humanoid.MoveToFinished:Wait() 
				end
			end
		end
	end	
end

goalEvent.OnServerEvent:Connect(newGoal)

DetectMousePos (local script)

local player = game:GetService("Players").LocalPlayer
local goalPos = game:GetService("ReplicatedStorage"):WaitForChild("goalPos")

local mouse = player:GetMouse()
mouse.Button1Down:Connect(function()
	goalPos:FireServer(mouse.Hit.Position, mouse.Target)
end)

Fixed grammatical error in title.

You forgot to put .Value

target.Parent.Selected.Value = false

Edit : It was giving you the error because it thinks “Selected” is a property of target.Parent, but you were specifying the value to false so you need to add .Value

1 Like

OH! :person_facepalming: I’m such a goof for forgetting that… Thanks for helping out.