Hello,
I am having a few issues regarding checks for if a child exists or not. The code below is a snippet of a bomb script, which checks the surrounding parts in a radius if they should be unlocked and/or unanchored. This is used in multiple scripts that create explosions (rockets, landmines, etc.)
-- create part and empty touch function
local Part = Instance.new("Part")
Part.Size = Vector3.new(12,12,12)
Part.CFrame= script.Parent.CFrame -- same position as the explosion
Part.Shape = Enum.PartType.Ball
Part.Anchored = true
Part.Transparency = 1
Part.CanCollide = false
Part.Parent = workspace
Part.Touched:Connect(function()
end)
-- find every touching brick and process them
local WithinExplosionRadius = Part:GetTouchingParts()
Part:Destroy()
for _,part in pairs(WithinExplosionRadius) do
if part:FindFirstChild("NoUnanchor") == false then -- wait for child didn't work either [Infinite yield possible on 'Workspace.STUFF.blocks.grass:WaitForChild("NoUnanchor")']
local NoUnanchorBool = Instance.new("BoolValue")
NoUnanchorBool.Parent = part
NoUnanchorBool.Value = false
end
if part:FindFirstChild("NoUnlock") == nil then -- tried this too, didn't work. 'if not' failed as well.
local NoUnlockBool = Instance.new("BoolValue")
NoUnlockBool.Parent = part
NoUnlockBool.Value = false
end
if part.NoUnanchor.Value == false then
part.Anchored = false
end
if part.NoUnlock.Value == false then
part.Locked = false
end
end
I wanted to utilise BoolValues to check if the brick is allowed to be edited. I did not want to add those values to every brick that will spawn or be in the game (including some bricks that will be generated via other scripts). The parts that don’t have the BoolValues before the check are allowed to be changed, as they are most likely to not break the game.
Instead of this working, this code results in the following:
NoUnanchor is not a valid member of Part "Workspace.STUFF.blocks.grass"
It errors out and halts entirely. It’s very plausible that I missed something very important that’s needed.
I tried many things to make this work (making it a variable (local bool = part:FindFirstChild("NoUnlock")
), wait for child instead of find first child, if not, == nil, == false) and I have run out of possible things to try.
Can you please help me figure out what went wrong? Is this a lost cause? Can BoolValues even be checked if they exist?
Regards, Dango360.