So, i'm trying to make this game where you run from someone and you can place walls to slow them off. But, it's suposed to kill the player if they spawn too much walls (5) in the span of 10 seconds. But i get the error on title and i don't know how to fix it. (by the way i'm not that great at scripting and my friend who does know lua helped me a bunch, if that matters) Here's the code. It highlights the 9th line, which also means line 22 won't work.
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local block = game.Workspace:FindFirstChild("Block", true)
local blockCount = 0
local blockTimer = 0
player.CharacterAdded:Connect(function(character)
character.Humanoid.MaxHealth = 1000
end)
mouse.Button1Down:Connect(function()
blockCount = blockCount + 1
local newBlock = block:Clone()
newBlock.Name = "Block"..blockCount
newBlock.Parent = game.Workspace
newBlock.CFrame = player.Character.Head.CFrame - player.Character.Head.CFrame.LookVector
if blockCount > 5 and tick() - blockTimer >= 10 then
print(player.Character.Humanoid)
wait(1)
player.Character.Humanoid:TakeDamage(1000)
blockCount = 0
blockTimer = 0
end)
delay(15, function()
newBlock:Destroy()
blockCount = blockCount - 1
end)
blockTimer = tick()
end)
game:GetService("RunService").Heartbeat:Connect(function()
if tick() - blockTimer >= 10 then
blockCount = 0
blockTimer = 0
end
end)
print(player)

6 comments
I recommend not putting the second argument in :WaitForChild(), because after 5 seconds and the child is still nonexistent (or nil) it will return nil.
Unlike without the second argument, which will yield forever until the child has been found.
Also, you said that the timeOut (or the second argument) default is 5, which is incorrect. You meant that after 5 seconds of the child still nonexistent, it will print a warning, not ending the function and return nil.
The timeOut argument is optional, btw.
I thought I edited that to feature it... I'll add it now though! Thanks!
Had to modify the script a bit cause the parentheses we're a bit messed up but it worked. Thanks.