Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

attempt to index boolean with 'Value' ???

error: > ServerScriptService.Rounds:143: attempt to index boolean with 'Value'

Code: https://imgur.com/a/oR6iDd2

im very confused and never had this error before...

--// Created: 		2022-10-09  12:14AM
--// Last Edited: 	2022-10-29	8:46PM

local roundLength = 30
local IntermissionLength = 5
local InRound   = game.ReplicatedStorage.InRound
local Status    = game.ReplicatedStorage.Status

local LobbySpawn    = workspace.Lobby_Spawn

local Spawn1 = workspace.Map_Spawn_1
local Spawn2 = workspace.Map_Spawn_2
local Spawn3 = workspace.Map_Spawn_3
local Spawn4 = workspace.Map_Spawn_4

local GameSpawn = {
    Spawn1,
    Spawn2,
    Spawn3,
    Spawn4
}

local MapSpawns = 1


local TotalPlayers = {}
local playing = {}



InRound.Changed:Connect(function()
    if InRound.Value == true then                                               --//On Game Start
        
		wait(1)
		
		
        for _, player in pairs(game.Players:GetChildren()) do                           --Map Spawns
            local char = player.Character

            char.HumanoidRootPart.CFrame = GameSpawn[MapSpawns].CFrame
            print ('Spawning at:'..MapSpawns)
            
            if MapSpawns <4 then
                MapSpawns += 1
            else 
                MapSpawns = 1 
            end

            player.Team = game.Teams.Players		

				table.insert(TotalPlayers, player.Name)                                         --Total Players
				if player.Team.Name == 'Players' then                                           --InGame Players
					table.insert(playing, player.Name)
					print(playing)

				local char = player.Character
				
				

				local function numPlayerCheck()
					if #playing == 0 then                                                               --0 Players Left
						print('Everyone Died.')
						Status.Value = 'Everyone has died.'

						wait(3)

						InRound = false


					elseif #playing == 1 and #TotalPlayers > 1 then                                     --1 Player Left
						local Winner = game:GetService("Players"):FindFirstChild(playing[1])

						Status.Value = (Winner.Name.. 'Has Won!')
						print(Winner.. ' has won!')

						wait(3)

						local PlayerCash = Winner.data.Cash.Value
						local leaderstats = Winner.leaderstats.Cash.Value

						leaderstats +=25
						PlayerCash += 25

						print(Winner.. 'now has: '.. PlayerCash..' Cash')
						InRound = false

					elseif #playing == 1 and #TotalPlayers == 1 then				                    --Only 1 Player in Server
						print('Only 1 Person in Server, Continuing Game.')
					end
				end
				
				
				char:WaitForChild('Humanoid').Died:Connect(function(plr)
					for i = 1, #playing do

						if playing[i] == player.Name then
							table.remove(playing, i)
							print('removed Player'.. i.. ' from table.')
							print(playing)
                            numPlayerCheck()
						end
					end
					player.Team = game.Teams.Lobby
				end)
				
			end
			
			
			--//Player Conditions
			
			
	    end

        
    elseif InRound.Value == false then                                              --//On Game End
        
        wait(1)
        for _, player in pairs(game.Players:GetChildren()) do
            local char = player.Character
            char.HumanoidRootPart.CFrame = LobbySpawn.CFrame
            player.Team = game.Teams.Lobby
        end

        
    end
end)






local function roundTimer()
    while wait() do
        for i = IntermissionLength, 1, -1 do                                            --Intermission Timer
            InRound.Value = false
            wait(1)
            Status.Value = ('Intermission: '..i..' Seconds Left.')          
        end

        for i = roundLength, 1, -1 do                                                   --Round Timer
            InRound.Value = true
            wait(1)
            Status.Value = ('Game:'..i..' Seconds Left.')
        end
    end
end

spawn(roundTimer)

1 answer

I'll give you understanding of what the error attempt to index ... with ... means. Indexing means that you are trying to get some property of an instance, say Color property of Part, in code it looks like this:

local color = Part.Color

^^^ Here I indexed Part with Color

This code ran without issues, but what if I try to index something that's not instance, say nil (non-existent value)...

local part = Workspace:FindFirstChid("Part") -- The part does not exist, I deleted it in Studio

local color = part.Color
-- the line above equal to the line below
local color = nil.Color

This would give an error saying attempt to index nil with Color because Part is nil. In your case the property is Value and the thing you are indexing is not an instance but a boolean, boolean is true or false:

local InRound = true

InRound.Value = false

This gives attempt to index boolean with Value error. The most likely cause of it is that when you created the variable InRound, you wrote this:

local InRound = ReplicatedStorage.InRound.Value
--- ^^^ InRound is a boolean, true or false, not an instance, it does not
-- have the Value property, boolean can only be in code, not in Explorer

Instead of this:

local InRound = ReplicatedStorage.InRound
--- ^^^ InRound is BooleanValue, Instance which can hold many properties
-- and one of them is Value which holds a boolean, true or false

You did not send the part where you create the variable, but seek for similar problem as above or send picture of it.

3 comments

0

omg my english is so gooood <3:)*****8

0

I wrote the variable as game.ReplicatedStorage.InRound, also, i added my code to the question so you can take a look, thanks.

0

see lines 67 and 85, you replaced the original BooleanValue with a boolean, you can come up with the solution yourself but just in case... InRound.Value = ...

This discussion is preserved as it was. New answers, comments, and votes are closed.