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

attempt to index nil with 'Value' ?

Hi thank you for your time and effort i want for all players to have a alive tag so i know when they are alive here is my code

	local builder=Instance.new("BoolValue")
	builder.Name="builder"
	for i,surface in pairs(surfaces) do
			for y,players in pairs(plrs) do
				local gamecharacter=players.Character or players.CharacterAdded:Wait()
				if gamecharacter then
					builder.Value=true
					builder.Parent=players
					local surfacespowns=surface:FindFirstChild("Spown"):GetChildren()
					wait(1)
					gamecharacter:FindFirstChild("HumanoidRootPart").CFrame=surfacespowns[math.random(1,#surfacespowns)].CFrame						
					game:GetService("ReplicatedStorage").Desider.CanCollide=false
					wait(30)
				else
					if not players then
						builder.Value=false
						builder.Parent=players	
						table.remove(plrs,i)
					end
				end
				
			end

and then when i want to verify it if plr:FindFirstChild("builder").Value==true then but it shows me these errors attempt to index nil with 'Value' ? and attempt to index bill with Parent thank you.

1 comment

0

id have to see the code where you're calling "if plr:FindFirstChild("builder").Value==true then" .. but that error means plr:FindFirstChild("builder") is not found or nil, so theres no property Value for it

2 answers

✓ Accepted answer

well bud, the thing is FindFirstChild can return nil.. in that case, then your code expression would be nil.Value==true then which is why you get the error attempt to index nil with 'Value' .. b/c again remember, FindFirstChild can return nil if there is no object with a matching name

so i recommend doing

local builder = plr:FindFirstChild("builder");
if(builder and builder.Value) then
	--code here
end

the and operator will return true if bpth it's arguments are true, if the first one is false, it will immediately return false, else it will check if the second one is also true

2 comments

0

thank you that solved it but i wanna ask how do i get the builder into the player i have done this local builder=Instance.new("BoolValue") builder.Name="builder" builder.Value=true builder.Parent=plr is it the right way

0

yes, you can also do local builder = Instance.new("BoolValue", player),  builder.Name = "builder"

Try using if plr:WaitForChild("builder").Value == true then

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