I’m checking if a character isn’t stunned or block broken in my combat game and this is happening.
if keycode == Enum.KeyCode.LeftShift and char:FindFirstChild("BlockBreak") == nil and char:FindFirstChild("Stun") == nil and char:FindFirstChild("eStun") == nil and player.PSD.status.Value == "ingame" then
The error
Players.Rahyulty.PlayerScripts.Run:23: attempt to index nil with 'FindFirstChild'
When you see that error “attempt to index nil with x” it means that the item before “x” is nil.
“x” in this case is “FindFirstChild”, so the thing before it (char) is nil. You can fix this error by adding a check for char:
if keycode == Enum.KeyCode.LeftShift and char and char:FindFirst....
local players = game:GetService("Players")
local player = players.LocalPlayer or players.PlayerAddded:Wait()
local character = player.Character or player.CharacterAdded:Wait()
local UIS = game:GetService("UserInputService")
UIS.InputBegan:Connect(function(key, proc)
if key.KeyCode == Enum.KeyCode.LeftShift and character:FindFirstChild("BlockBreak") then
--do code
end
end)
Your error message indicates that “char” was incorrectly defined/referenced (as it is nil), so you end up attempting to call “WaitForChild()” to look for a child named “BlockBreak” using a nil value.