I want to achieve a simple chess system. The problem is I do not know how I will detect checkmate (when the king has nowhere to go and is threatened)
Hello, If you mean having a piece that is close to the king, leaving it no place to go, then you would most likely have to find the magnitude of the king to another piece. You may want to adjust a few things before using the script, such as the location of the king, other pieces, and the distance. So I’m guessing it is in workspace.
local King = game.workspace:WaitFirstChild("King") --Change to King Location
local Object = game.Workspace:WaitForChild("Pawn") -- Change location & name
local Distance = (Object.Position - King.Position).Magnitude -- Finds the Distance
print(Distance) -- Prints the Distance
while wait() do -- Repeats
if Distance >= 10 then -- Change to whatever distance
print("Checkmate")
end
end
Let me know if this works!