Failed attempt at checking for a boolvalue

Recently I’ve been trying to check if a player has a certain BoolValue attached to it, if it doesn’t then it’ll create one. But it’s only returning nil values and not creating a value parented to the person. I’ve tried a lot of “solutions” but none of them work.

code: (serverside)

PlayerKilledByZombie.Event:Connect(function(Name)
	if Name:GetChildren("IsZombie") == nil then
		local IsZombie = Instance.new("BoolValue")
		IsZombie.Parent = Name
		IsZombie.Value = false
		IsZombie.Name = "IsZombie"
		ChangePlayerIntoZombieKilled:Fire(Name)
	end
end)
3 Likes

this is not


GetChildren() returns a table of children and takes no parameters.

I think you are looking for FindFirstChild(childName)

1 Like

Try Using,

Name:FindFirstChild("IsZombie")

This is if you want to check if ‘IsZombie’ is a child of Name

I’ve tried using that as well but it doesnt work, it returns a nil value and doesnt create a value

What exactly do you want the program to do?

check if the player has a value named IsZombie, if they dont it creates IsZombie parented to the player so they can attack when they turn into a zombie.

And how are you telling that the Instance has not been created?

Just by looking in the explorer?

Yes, I’d assume it would show up in the explorer

Yeah, it would, I was just checking because I’ve had it before where it doesn’t pick up on the client not server.

Just try creating the Instance, outside of the if statement, and just run the line:

Instance.new("BoolValue", Name)

Check if its created

So like this

PlayerKilledByZombie.Event:Connect(function(Name)
	if Name:FindFirstChild("IsZombie") == nil then
		local IsZombie = Instance.new("BoolValue")
		IsZombie.Parent = Name
		IsZombie.Value = false
		IsZombie.Name = "IsZombie"
		ChangePlayerIntoZombieKilled:Fire(Name)
	end
    Instance.new("BoolValue", Name)
end)

Yeah no it’s not creating one even outside of the if statement

What if you just:

print(Name:FindFirstChild("IsZombie"))

Does that run?

What is Name? Cud u show it in the heirarchy?

If not there may be a problem with the actual event

When I said

Instance.new("BoolValue", Name)

It just means that the bool value’s parent is going to be the variable Name

It’s just a quicker way of doing it.

Also keep in mind tht this wont work if the boolvalue a descendant of Name. i.e children of childrrn of Name.

In tht case set the recursive param as true.

it doesnt run at all, it just replies with a nil value

Is it a descendant or child? The boolval isZombie?

the name is what’s sent from another server script

 if RayHitBox.Instance.Parent.Humanoid.Health <= 0 then
	local PlayerKilledByZombie = script.Parent.PlayerKilledByZombie				 
    PlayerKilledByZombie:Fire(Name)
end