BoolValue not setting to true in leaderstats

I’m trying to get my BoolValues set to true, no errors, and I don’t know what else to do. I don’t want to make a if statement to check if its false because of the characters. Do I need to add this to a new / different script?

local function playerJoined(player)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player

	local character = Instance.new("Folder")
	character.Name = "BoughtChar"
	character.Parent = player

	local character2 =Instance.new("Folder")
	character2.Name = "EquippedChar"
	character2.Parent = player

	local gamepasses = Instance.new("Folder")
	gamepasses.Name = "Gamepass"
	gamepasses.Parent = player

	local wins = Instance.new("IntValue")
	wins.Name = "Wins"
	wins.Parent = leaderstats
	wins.Value = 0

	local coins = Instance.new("IntValue")
	coins.Name = "Coins"
	coins.Parent = leaderstats
	coins.Value = 0

	-- Characters --
	local defaultCharacter = Instance.new("BoolValue")
	defaultCharacter.Name = "char1"
	defaultCharacter.Parent = character
	defaultCharacter.Value = true

	local equippedDefault = Instance.new("BoolValue")
	equippedDefault.Name = "char1"
	equippedDefault.Parent = character2
	equippedDefault.Value = true

	local char2 = Instance.new("BoolValue")
	char2.Name = "char2"
	char2.Parent=  character
	char2.Value = false

	local equippedChar2 = Instance.new("BoolValue")
	equippedChar2.Name = "char2"
	equippedChar2.Parent = character2
	equippedChar2.Value = false

	-- GamePasses --
	local rainbowText = Instance.new("BoolValue")
	rainbowText.Name = "RainbowText"
	rainbowText.Parent = gamepasses
	rainbowText.Value = false

	local coinMulti = Instance.new("IntValue")
	coinMulti.Name = "CoinMultiplier"
	coinMulti.Parent = gamepasses
	coinMulti.Value = 1

	-- Do not put in Datastore --
	local statistics = Instance.new("Folder")
	statistics.Name = "Statistics"
	statistics.Parent = player

	local inGame = Instance.new("BoolValue")
	inGame.Name = "inGame"
	inGame.Parent = statistics
	inGame.Value = false

	local alpha = Instance.new("BoolValue")
	alpha.Name = "Alpha"
	alpha.Parent = player
	alpha.Value = true 
end

game.Players.PlayerAdded:Connect(playerJoined)

I’m not sure what the problem is but you could try to make a variable for the BoolValue’s Value and then set it to false or true.

local rainbowTextValue = rainbowText.Value

rainbowTextValue = false/true

You can also set the parent of a new instance in the same line you make it in:

local rainbowText = Instance.new("BoolValue", player)

rather than:

local rainbowText = Instance.new("BoolValue")
rainbowText.Parent = gamepasses

This won’t help with your values problem but it’s more efficient. Hope this works!

I’m not sure if it harms performance in this case, but it definitely harms performance in the case of parts, I’ll link the post that says this when I find it. Just in case you start using the second argument of Instance.new() everywhere.
Edit: Post

Ah, I didn’t know it harms performance with parts. I haven’t been able to tell a different when using it for values such as a leaderboard. Thanks for letting me know!