Welding to a player doesn't work and error code

I am trying to make a capture the flag system. What’s supposed to happen is when you touch a green circle, the display flag disappears and a smaller flag I have in replicated storage is supposed to duplicate and attach onto the Humanoid Root Part (The Back of the player). The smaller flag is a model. The first part of the script works well, it goes through with no error, but when I run back on the circle, I get the error:
Workspace.BlueBase.CapturePart.Script:12: attempt to index boolean with ‘Value’

The, “BLUE_CAPTURED_VALUE” is a global boolean variable.

Script:

local BLUE_CAPTURED_VALUE = game.ReplicatedFirst.BlueCaptured
local TOUCH_PART = script.Parent
local FLAG = script.Parent.Parent.BlueFlag
local Players = game:GetService("Players")

local debounce = false
TOUCH_PART.Touched:Connect(function(hit)
	if not debounce then
		debounce = true
		if hit then
			local player = Players:GetPlayerFromCharacter(hit.Parent)
				if player and player.TeamColor == BrickColor.new("Bright red") and BLUE_CAPTURED_VALUE.Value == false then
				FLAG.Union.CanCollide = false
				FLAG.Part.CanCollide = false
				FLAG.Union.Transparency = 1
				FLAG.Part.Transparency = 1
				FLAG.Part.ParticleEmitter.Enabled = false
				print("1")
				local TORSO = player:FindFirstChild("Humanoid")
				local CAPTURED_FLAG = game.ReplicatedStorage.PlayerFlags.BlueTeamFlag:Clone()
				CAPTURED_FLAG.Parent = player
				print("2")
				local WELD = Instance.new("Weld", TORSO)
				WELD.C0 = CFrame.new(0,0,2)
				WELD.C1 = CFrame.new(0,0,2)
				WELD.Part0 = CAPTURED_FLAG.PrimaryPart
				WELD.Part1 = TORSO
				print("3")
				BLUE_CAPTURED_VALUE = true
			end
		end
		wait(0.5)
		debounce = false
	end
end)

Any idea why I’m getting this error and why the smaller flag is not appearing on the player’s back?

To get the value of the boolean object, you use .Value like so BLUE_CAPTURED_VALUE.Value.

What this line (BLUE_CAPTURED_VALUE["Value"]) is trying to do is find a child of BLUE_CAPTURED_VALUE named Value

Need to change that part of the script because I already used “.Value” and it popped up with the same error.

Then I’m thinking this might be causing the error:

BLUE_CAPTURED_VALUE = true

should be:

BLUE_CAPTURED_VALUE.Value = true
1 Like